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

Function ByteOffsetToRunePosition

backend/plugin/parser/plsql/omni.go:128–151  ·  view source on GitHub ↗

ByteOffsetToRunePosition converts a byte offset in sql to a 1-based line:column where column is measured in Unicode code points (runes), matching storepb.Position semantics.

(sql string, byteOffset int)

Source from the content-addressed store, hash-verified

126// ByteOffsetToRunePosition converts a byte offset in sql to a 1-based line:column
127// where column is measured in Unicode code points (runes), matching storepb.Position semantics.
128func ByteOffsetToRunePosition(sql string, byteOffset int) *storepb.Position {
129 if byteOffset > len(sql) {
130 byteOffset = len(sql)
131 }
132
133 line := int32(1)
134 runeCol := int32(0) // 0-based rune count on current line
135 i := 0
136 for i < byteOffset {
137 r, size := utf8.DecodeRuneInString(sql[i:])
138 if r == '\n' {
139 line++
140 runeCol = 0
141 } else {
142 runeCol++
143 }
144 i += size
145 }
146
147 return &storepb.Position{
148 Line: line,
149 Column: runeCol + 1, // convert to 1-based
150 }
151}
152
153func convertOmniError(err error, stmt base.Statement) error {
154 var parseErr *oracleparser.ParseError

Callers 2

convertOmniErrorFunction · 0.70

Calls

no outgoing calls

Tested by 1