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

Method Position

backend/plugin/parser/base/position.go:27–59  ·  view source on GitHub ↗

Position returns the 1-based line:column position for byteOffset.

(byteOffset int)

Source from the content-addressed store, hash-verified

25
26// Position returns the 1-based line:column position for byteOffset.
27func (m *ByteOffsetPositionMapper) Position(byteOffset int) *storepb.Position {
28 if byteOffset < 0 {
29 byteOffset = 0
30 }
31 if byteOffset > len(m.sql) {
32 byteOffset = len(m.sql)
33 }
34 if byteOffset < m.byteOffset {
35 return byteOffsetToRunePosition(m.sql, byteOffset)
36 }
37
38 for m.byteOffset < byteOffset {
39 r, size := utf8.DecodeRuneInString(m.sql[m.byteOffset:])
40 switch r {
41 case '\r':
42 m.line++
43 m.runeCol = 0
44 case '\n':
45 if m.byteOffset == 0 || m.sql[m.byteOffset-1] != '\r' {
46 m.line++
47 m.runeCol = 0
48 }
49 default:
50 m.runeCol++
51 }
52 m.byteOffset += size
53 }
54
55 return &storepb.Position{
56 Line: m.line,
57 Column: m.runeCol + 1,
58 }
59}
60
61func byteOffsetToRunePosition(sql string, byteOffset int) *storepb.Position {
62 line := int32(1)

Callers 15

convertStatementsFunction · 0.95
DiagnoseFunction · 0.95
SplitSQLFunction · 0.95
SplitSQLFunction · 0.95
ParseCosmosDBFunction · 0.95
SplitSQLFunction · 0.95
prepareTransformationFunction · 0.95
SplitSQLFunction · 0.95
SplitSQLForCompletionFunction · 0.95
prepareTransformationFunction · 0.95

Calls 1

byteOffsetToRunePositionFunction · 0.85