MCPcopy
hub / github.com/tidwall/gjson / tostr

Function tostr

gjson.go:609–651  ·  view source on GitHub ↗
(json string)

Source from the content-addressed store, hash-verified

607}
608
609func tostr(json string) (raw string, str string) {
610 // expects that the lead character is a '"'
611 for i := 1; i < len(json); i++ {
612 if json[i] > '\\' {
613 continue
614 }
615 if json[i] == '"' {
616 return json[:i+1], json[1:i]
617 }
618 if json[i] == '\\' {
619 i++
620 for ; i < len(json); i++ {
621 if json[i] > '\\' {
622 continue
623 }
624 if json[i] == '"' {
625 // look for an escaped slash
626 if json[i-1] == '\\' {
627 n := 0
628 for j := i - 2; j > 0; j-- {
629 if json[j] != '\\' {
630 break
631 }
632 n++
633 }
634 if n%2 == 0 {
635 continue
636 }
637 }
638 return json[:i+1], unescape(json[1:i])
639 }
640 }
641 var ret string
642 if i+1 < len(json) {
643 ret = json[:i+1]
644 } else {
645 ret = json[:i]
646 }
647 return ret, unescape(json[1:i])
648 }
649 }
650 return json, json[1:]
651}
652
653// Exists returns true if value exists.
654//

Callers 2

arrayOrMapMethod · 0.85
ParseFunction · 0.85

Calls 1

unescapeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…