MCPcopy
hub / github.com/sqldef/sqldef / scanBalancedParenthesizedSQL

Function scanBalancedParenthesizedSQL

database/mssql/parser.go:300–333  ·  view source on GitHub ↗
(sql string, start int)

Source from the content-addressed store, hash-verified

298}
299
300func scanBalancedParenthesizedSQL(sql string, start int) (string, int, bool) {
301 if start >= len(sql) || sql[start] != '(' {
302 return "", start, false
303 }
304
305 depth := 0
306 for i := start; i < len(sql); {
307 switch {
308 case hasLineCommentPrefix(sql, i):
309 i = scanLineComment(sql, i)
310 case hasBlockCommentPrefix(sql, i):
311 i = scanBlockComment(sql, i)
312 case sql[i] == '\'':
313 i = scanSingleQuotedString(sql, i)
314 case sql[i] == '"':
315 i = scanDoubleQuotedString(sql, i)
316 case sql[i] == '[':
317 i = scanBracketIdentifier(sql, i)
318 case sql[i] == '(':
319 depth++
320 i++
321 case sql[i] == ')':
322 depth--
323 i++
324 if depth == 0 {
325 return sql[start:i], i, true
326 }
327 default:
328 i++
329 }
330 }
331
332 return "", start, false
333}
334
335func hasKeywordAt(sql string, pos int, keyword string) bool {
336 if pos < 0 || pos+len(keyword) > len(sql) {

Callers 2

stripOuterSQLParensFunction · 0.85

Calls 7

hasLineCommentPrefixFunction · 0.85
scanLineCommentFunction · 0.85
hasBlockCommentPrefixFunction · 0.85
scanBlockCommentFunction · 0.85
scanSingleQuotedStringFunction · 0.85
scanDoubleQuotedStringFunction · 0.85
scanBracketIdentifierFunction · 0.85

Tested by

no test coverage detected