MCPcopy Create free account
hub / github.com/dolthub/doltgresql / gobbleString

Method gobbleString

postgres/parser/sem/tree/parse_array.go:60–85  ·  view source on GitHub ↗

gobbleString advances the parser for the remainder of the current string until it sees a non-escaped termination character, as specified by isTerminatingChar, returning the resulting string, not including the termination character.

(isTerminatingChar func(ch byte) bool)

Source from the content-addressed store, hash-verified

58// isTerminatingChar, returning the resulting string, not including the
59// termination character.
60func (p *parseState) gobbleString(isTerminatingChar func(ch byte) bool) (out string, err error) {
61 var result bytes.Buffer
62 start := 0
63 i := 0
64 for i < len(p.s) && !isTerminatingChar(p.s[i]) {
65 // In these strings, we just encode directly the character following a
66 // '\', even if it would normally be an escape sequence.
67 if i < len(p.s) && p.s[i] == '\\' {
68 result.WriteString(p.s[start:i])
69 i++
70 if i < len(p.s) {
71 result.WriteByte(p.s[i])
72 i++
73 }
74 start = i
75 } else {
76 i++
77 }
78 }
79 if i >= len(p.s) {
80 return "", malformedError
81 }
82 result.WriteString(p.s[start:i])
83 p.s = p.s[i:]
84 return result.String(), nil
85}
86
87type parseState struct {
88 s string

Callers 2

parseQuotedStringMethod · 0.95
parseUnquotedStringMethod · 0.95

Calls 2

WriteStringMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected