ByteOffset is just like ToCharPos except it counts bytes instead of runes
(pos Loc, buf *Buffer)
| 137 | |
| 138 | // ByteOffset is just like ToCharPos except it counts bytes instead of runes |
| 139 | func ByteOffset(pos Loc, buf *Buffer) int { |
| 140 | x, y := pos.X, pos.Y |
| 141 | loc := 0 |
| 142 | for i := 0; i < y; i++ { |
| 143 | // + 1 for the newline |
| 144 | loc += len(buf.Line(i)) + 1 |
| 145 | } |
| 146 | loc += len(buf.Line(y)[:x]) |
| 147 | return loc |
| 148 | } |
| 149 | |
| 150 | // clamps a loc within a buffer |
| 151 | func clamp(pos Loc, la *LineArray) Loc { |