offsetToLineColumn converts an absolute offset to line and column
(content string, offset int)
| 558 | |
| 559 | // offsetToLineColumn converts an absolute offset to line and column |
| 560 | func offsetToLineColumn(content string, offset int) (line, col int) { |
| 561 | if offset < 0 { |
| 562 | return 0, 0 |
| 563 | } |
| 564 | if offset >= len(content) { |
| 565 | offset = len(content) - 1 |
| 566 | if offset < 0 { |
| 567 | return 0, 0 |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | line = 0 |
| 572 | col = 0 |
| 573 | for i := 0; i < offset && i < len(content); i++ { |
| 574 | if content[i] == '\n' { |
| 575 | line++ |
| 576 | col = 0 |
| 577 | } else { |
| 578 | col++ |
| 579 | } |
| 580 | } |
| 581 | return |
| 582 | } |
| 583 | |
| 584 | // isWhitespace returns true if c is a whitespace character |
| 585 | func isWhitespace(c byte) bool { |
no outgoing calls