MCPcopy Index your code
hub / github.com/bytebase/bytebase / lineColumnToByteOffset

Function lineColumnToByteOffset

backend/plugin/parser/plsql/completion.go:93–123  ·  view source on GitHub ↗
(sql string, line, column int)

Source from the content-addressed store, hash-verified

91}
92
93func lineColumnToByteOffset(sql string, line, column int) int {
94 currentLine := 1
95 for i := 0; i < len(sql); i++ {
96 if currentLine == line {
97 pos := i
98 for c := 0; c < column && pos < len(sql); {
99 r, size := utf8.DecodeRuneInString(sql[pos:])
100 if r == '\n' {
101 return pos
102 }
103 unitCount := 1
104 if r > 0xFFFF {
105 unitCount = 2
106 }
107 if c+unitCount > column {
108 return pos
109 }
110 pos += size
111 c += unitCount
112 }
113 if pos > len(sql) {
114 return len(sql)
115 }
116 return pos
117 }
118 if sql[i] == '\n' {
119 currentLine++
120 }
121 }
122 return len(sql)
123}
124
125func findCaretTokenIndex(tokens []oracleparser.Token, byteOffset int) int {
126 for i, tok := range tokens {

Callers 2

computeSQLAndByteOffsetFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected