MCPcopy Create free account
hub / github.com/bytebase/bytebase / lastKeywordIndex

Function lastKeywordIndex

backend/plugin/parser/partiql/completion.go:197–213  ·  view source on GitHub ↗

lastKeywordIndex returns the index of the last occurrence of kw in s that appears at a word boundary (not inside an identifier). Returns -1 if not found. Both s and kw must be uppercase.

(s, kw string)

Source from the content-addressed store, hash-verified

195// that appears at a word boundary (not inside an identifier). Returns -1
196// if not found. Both s and kw must be uppercase.
197func lastKeywordIndex(s, kw string) int {
198 search := s
199 for {
200 idx := strings.LastIndex(search, kw)
201 if idx < 0 {
202 return -1
203 }
204 end := idx + len(kw)
205 startOk := idx == 0 || !isIdentRune(rune(search[idx-1]))
206 endOk := end >= len(search) || !isIdentRune(rune(search[end]))
207 if startOk && endOk {
208 return idx
209 }
210 // Shrink the search window and try again.
211 search = search[:idx]
212 }
213}
214
215func isIdentRune(r rune) bool {
216 return (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') ||

Callers 1

isColumnContextFunction · 0.85

Calls 1

isIdentRuneFunction · 0.85

Tested by

no test coverage detected