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

Function byteOffsetToPosition

backend/plugin/parser/doris/doris.go:144–158  ·  view source on GitHub ↗

byteOffsetToPosition converts a 0-based byte offset to a 1-based line and 1-based column (in runes).

(s string, offset int)

Source from the content-addressed store, hash-verified

142// byteOffsetToPosition converts a 0-based byte offset to a 1-based line and
143// 1-based column (in runes).
144func byteOffsetToPosition(s string, offset int) (line, col int) {
145 line = 1
146 col = 1
147 for i := 0; i < offset && i < len(s); {
148 r, size := utf8.DecodeRuneInString(s[i:])
149 if r == '\n' {
150 line++
151 col = 1
152 } else {
153 col++
154 }
155 i += size
156 }
157 return line, col
158}

Callers 1

convertParseErrorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected