The following functions require a buffer to know where newlines are Diff returns the distance between two locations
(a, b Loc, buf *LineArray)
| 61 | |
| 62 | // Diff returns the distance between two locations |
| 63 | func DiffLA(a, b Loc, buf *LineArray) int { |
| 64 | if a.Y == b.Y { |
| 65 | if a.X > b.X { |
| 66 | return a.X - b.X |
| 67 | } |
| 68 | return b.X - a.X |
| 69 | } |
| 70 | |
| 71 | // Make sure a is guaranteed to be less than b |
| 72 | if b.LessThan(a) { |
| 73 | a, b = b, a |
| 74 | } |
| 75 | |
| 76 | loc := 0 |
| 77 | for i := a.Y + 1; i < b.Y; i++ { |
| 78 | // + 1 for the newline |
| 79 | loc += util.CharacterCount(buf.LineBytes(i)) + 1 |
| 80 | } |
| 81 | loc += util.CharacterCount(buf.LineBytes(a.Y)) - a.X + b.X + 1 |
| 82 | return loc |
| 83 | } |
| 84 | |
| 85 | // This moves the location one character to the right |
| 86 | func (l Loc) right(buf *LineArray) Loc { |
no test coverage detected