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)
| 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. |
| 128 | func 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 | |
| 153 | func convertOmniError(err error, stmt base.Statement) error { |
| 154 | var parseErr *oracleparser.ParseError |
no outgoing calls