MCPcopy
hub / github.com/go-yaml/yaml / yaml_parser_scan_flow_scalar

Function yaml_parser_scan_flow_scalar

scannerc.go:2435–2688  ·  view source on GitHub ↗

Scan a quoted scalar.

(parser *yaml_parser_t, token *yaml_token_t, single bool)

Source from the content-addressed store, hash-verified

2433
2434// Scan a quoted scalar.
2435func yaml_parser_scan_flow_scalar(parser *yaml_parser_t, token *yaml_token_t, single bool) bool {
2436 // Eat the left quote.
2437 start_mark := parser.mark
2438 skip(parser)
2439
2440 // Consume the content of the quoted scalar.
2441 var s, leading_break, trailing_breaks, whitespaces []byte
2442 for {
2443 // Check that there are no document indicators at the beginning of the line.
2444 if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) {
2445 return false
2446 }
2447
2448 if parser.mark.column == 0 &&
2449 ((parser.buffer[parser.buffer_pos+0] == '-' &&
2450 parser.buffer[parser.buffer_pos+1] == '-' &&
2451 parser.buffer[parser.buffer_pos+2] == '-') ||
2452 (parser.buffer[parser.buffer_pos+0] == '.' &&
2453 parser.buffer[parser.buffer_pos+1] == '.' &&
2454 parser.buffer[parser.buffer_pos+2] == '.')) &&
2455 is_blankz(parser.buffer, parser.buffer_pos+3) {
2456 yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar",
2457 start_mark, "found unexpected document indicator")
2458 return false
2459 }
2460
2461 // Check for EOF.
2462 if is_z(parser.buffer, parser.buffer_pos) {
2463 yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar",
2464 start_mark, "found unexpected end of stream")
2465 return false
2466 }
2467
2468 // Consume non-blank characters.
2469 leading_blanks := false
2470 for !is_blankz(parser.buffer, parser.buffer_pos) {
2471 if single && parser.buffer[parser.buffer_pos] == '\'' && parser.buffer[parser.buffer_pos+1] == '\'' {
2472 // Is is an escaped single quote.
2473 s = append(s, '\'')
2474 skip(parser)
2475 skip(parser)
2476
2477 } else if single && parser.buffer[parser.buffer_pos] == '\'' {
2478 // It is a right single quote.
2479 break
2480 } else if !single && parser.buffer[parser.buffer_pos] == '"' {
2481 // It is a right double quote.
2482 break
2483
2484 } else if !single && parser.buffer[parser.buffer_pos] == '\\' && is_break(parser.buffer, parser.buffer_pos+1) {
2485 // It is an escaped line break.
2486 if parser.unread < 3 && !yaml_parser_update_buffer(parser, 3) {
2487 return false
2488 }
2489 skip(parser)
2490 skip_line(parser)
2491 leading_blanks = true
2492 break

Callers 1

Calls 12

skipFunction · 0.85
is_blankzFunction · 0.85
is_zFunction · 0.85
is_breakFunction · 0.85
skip_lineFunction · 0.85
is_hexFunction · 0.85
as_hexFunction · 0.85
readFunction · 0.85
is_blankFunction · 0.85
read_lineFunction · 0.85

Tested by

no test coverage detected