MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / gobbleString

Method gobbleString

pkg/sql/sem/tree/parse_array.go:46–71  ·  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

44// isTerminatingChar, returning the resulting string, not including the
45// termination character.
46func (p *parseState) gobbleString(isTerminatingChar func(ch byte) bool) (out string, err error) {
47 var result bytes.Buffer
48 start := 0
49 i := 0
50 for i < len(p.s) && !isTerminatingChar(p.s[i]) {
51 // In these strings, we just encode directly the character following a
52 // '\', even if it would normally be an escape sequence.
53 if i < len(p.s) && p.s[i] == '\\' {
54 result.WriteString(p.s[start:i])
55 i++
56 if i < len(p.s) {
57 result.WriteByte(p.s[i])
58 i++
59 }
60 start = i
61 } else {
62 i++
63 }
64 }
65 if i >= len(p.s) {
66 return "", malformedError
67 }
68 result.WriteString(p.s[start:i])
69 p.s = p.s[i:]
70 return result.String(), nil
71}
72
73type parseState struct {
74 s string

Callers 2

parseQuotedStringMethod · 0.95
parseUnquotedStringMethod · 0.95

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected