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

Function lineOffsetToBytePos

backend/plugin/parser/tidb/completion.go:526–543  ·  view source on GitHub ↗

lineOffsetToBytePos converts a 1-based line number and 0-based character (rune) offset to a 0-based byte position in the string.

(s string, line, offset int)

Source from the content-addressed store, hash-verified

524// lineOffsetToBytePos converts a 1-based line number and 0-based character
525// (rune) offset to a 0-based byte position in the string.
526func lineOffsetToBytePos(s string, line, offset int) int {
527 pos := 0
528 currentLine := 1
529 for pos < len(s) && currentLine < line {
530 if s[pos] == '\n' {
531 currentLine++
532 }
533 pos++
534 }
535 for i := 0; i < offset && pos < len(s); i++ {
536 _, size := utf8.DecodeRuneInString(s[pos:])
537 pos += size
538 }
539 if pos > len(s) {
540 return len(s)
541 }
542 return pos
543}
544
545// currentStatement returns the statement containing byte position pos within
546// statement, along with pos translated to an offset within that statement. It

Callers 1

CompletionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected