MCPcopy Index your code
hub / github.com/segmentio/encoding / parseStringUnquote

Method parseStringUnquote

json/parse.go:477–558  ·  view source on GitHub ↗
(b []byte, r []byte)

Source from the content-addressed store, hash-verified

475}
476
477func (d decoder) parseStringUnquote(b []byte, r []byte) ([]byte, []byte, bool, error) {
478 s, b, k, err := d.parseString(b)
479 if err != nil {
480 return s, b, false, err
481 }
482
483 s = s[1 : len(s)-1] // trim the quotes
484
485 if k == Unescaped {
486 return s, b, false, nil
487 }
488
489 if r == nil {
490 r = make([]byte, 0, len(s))
491 }
492
493 for len(s) != 0 {
494 i := bytes.IndexByte(s, '\\')
495
496 if i < 0 {
497 r = appendCoerceInvalidUTF8(r, s)
498 break
499 }
500
501 r = appendCoerceInvalidUTF8(r, s[:i])
502 s = s[i+1:]
503
504 c := s[0]
505 switch c {
506 case '"', '\\', '/':
507 // simple escaped character
508 case 'n':
509 c = '\n'
510
511 case 'r':
512 c = '\r'
513
514 case 't':
515 c = '\t'
516
517 case 'b':
518 c = '\b'
519
520 case 'f':
521 c = '\f'
522
523 case 'u':
524 s = s[1:]
525
526 r1, n1, err := d.parseUnicode(s)
527 if err != nil {
528 return r, b, true, err
529 }
530 s = s[n1:]
531
532 if utf16.IsSurrogate(r1) {
533 if !hasPrefix(s, `\u`) {
534 r1 = unicode.ReplacementChar

Callers 9

TestParseStringUnquoteFunction · 0.95
decodeStringMethod · 0.95
decodeFromStringMethod · 0.95
decodeFromStringToIntMethod · 0.95
decodeBytesMethod · 0.95
decodeStructMethod · 0.95
decodeTextUnmarshalerMethod · 0.95
AppendUnquoteMethod · 0.95
StringMethod · 0.80

Calls 6

parseStringMethod · 0.95
parseUnicodeMethod · 0.95
appendCoerceInvalidUTF8Function · 0.85
hasPrefixFunction · 0.85
appendRuneFunction · 0.85
syntaxErrorFunction · 0.85

Tested by 1

TestParseStringUnquoteFunction · 0.76