Function
byteOffsetToRunePosition
(sql string, byteOffset int)
Source from the content-addressed store, hash-verified
| 59 | } |
| 60 | |
| 61 | func byteOffsetToRunePosition(sql string, byteOffset int) *storepb.Position { |
| 62 | line := int32(1) |
| 63 | runeCol := int32(0) |
| 64 | i := 0 |
| 65 | for i < byteOffset { |
| 66 | r, size := utf8.DecodeRuneInString(sql[i:]) |
| 67 | switch r { |
| 68 | case '\r': |
| 69 | line++ |
| 70 | runeCol = 0 |
| 71 | case '\n': |
| 72 | if i == 0 || sql[i-1] != '\r' { |
| 73 | line++ |
| 74 | runeCol = 0 |
| 75 | } |
| 76 | default: |
| 77 | runeCol++ |
| 78 | } |
| 79 | i += size |
| 80 | } |
| 81 | |
| 82 | return &storepb.Position{ |
| 83 | Line: line, |
| 84 | Column: runeCol + 1, |
| 85 | } |
| 86 | } |
Tested by
no test coverage detected