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

Function yaml_parser_scan_uri_escapes

scannerc.go:2144–2187  ·  view source on GitHub ↗

Decode an URI-escape sequence corresponding to a single UTF-8 character.

(parser *yaml_parser_t, directive bool, start_mark yaml_mark_t, s *[]byte)

Source from the content-addressed store, hash-verified

2142
2143// Decode an URI-escape sequence corresponding to a single UTF-8 character.
2144func yaml_parser_scan_uri_escapes(parser *yaml_parser_t, directive bool, start_mark yaml_mark_t, s *[]byte) bool {
2145
2146 // Decode the required number of characters.
2147 w := 1024
2148 for w > 0 {
2149 // Check for a URI-escaped octet.
2150 if parser.unread < 3 && !yaml_parser_update_buffer(parser, 3) {
2151 return false
2152 }
2153
2154 if !(parser.buffer[parser.buffer_pos] == '%' &&
2155 is_hex(parser.buffer, parser.buffer_pos+1) &&
2156 is_hex(parser.buffer, parser.buffer_pos+2)) {
2157 return yaml_parser_set_scanner_tag_error(parser, directive,
2158 start_mark, "did not find URI escaped octet")
2159 }
2160
2161 // Get the octet.
2162 octet := byte((as_hex(parser.buffer, parser.buffer_pos+1) << 4) + as_hex(parser.buffer, parser.buffer_pos+2))
2163
2164 // If it is the leading octet, determine the length of the UTF-8 sequence.
2165 if w == 1024 {
2166 w = width(octet)
2167 if w == 0 {
2168 return yaml_parser_set_scanner_tag_error(parser, directive,
2169 start_mark, "found an incorrect leading UTF-8 octet")
2170 }
2171 } else {
2172 // Check if the trailing octet is correct.
2173 if octet&0xC0 != 0x80 {
2174 return yaml_parser_set_scanner_tag_error(parser, directive,
2175 start_mark, "found an incorrect trailing UTF-8 octet")
2176 }
2177 }
2178
2179 // Copy the octet and move the pointers.
2180 *s = append(*s, octet)
2181 skip(parser)
2182 skip(parser)
2183 skip(parser)
2184 w--
2185 }
2186 return true
2187}
2188
2189// Scan a block scalar.
2190func yaml_parser_scan_block_scalar(parser *yaml_parser_t, token *yaml_token_t, literal bool) bool {

Callers 1

yaml_parser_scan_tag_uriFunction · 0.85

Calls 6

is_hexFunction · 0.85
as_hexFunction · 0.85
widthFunction · 0.85
skipFunction · 0.85

Tested by

no test coverage detected