MCPcopy Create free account
hub / github.com/PostHog/duckgres / skipCommentsAndSpace

Function skipCommentsAndSpace

server/usersecrets/classify.go:175–208  ·  view source on GitHub ↗

skipCommentsAndSpace removes leading whitespace, line comments (--) and block comments (/* */, nested) from s. Returns ok=false on an unterminated block comment.

(s string)

Source from the content-addressed store, hash-verified

173// block comments (/* */, nested) from s. Returns ok=false on an unterminated
174// block comment.
175func skipCommentsAndSpace(s string) (string, bool) {
176 for {
177 s = strings.TrimLeft(s, " \t\r\n")
178 switch {
179 case strings.HasPrefix(s, "--"):
180 idx := strings.IndexByte(s, '\n')
181 if idx < 0 {
182 return "", true
183 }
184 s = s[idx+1:]
185 case strings.HasPrefix(s, "/*"):
186 depth := 1
187 i := 2
188 for i < len(s) && depth > 0 {
189 switch {
190 case strings.HasPrefix(s[i:], "/*"):
191 depth++
192 i += 2
193 case strings.HasPrefix(s[i:], "*/"):
194 depth--
195 i += 2
196 default:
197 i++
198 }
199 }
200 if depth > 0 {
201 return "", false
202 }
203 s = s[i:]
204 default:
205 return s, true
206 }
207 }
208}
209
210// hasTrailingStatement reports whether query contains a top-level semicolon
211// (outside string literals, quoted identifiers, and comments) followed by

Callers 3

parseSecretDDLHeadFunction · 0.85
hasTrailingStatementFunction · 0.85
skipSpaceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected