mirror of
https://github.com/kovetskiy/mark.git
synced 2026-04-19 12:41:13 +00:00
20 lines
364 B
Go
20 lines
364 B
Go
package renderer
|
|
|
|
// GetLineCol returns the 1-based line and column for a given byte offset in the source.
|
|
func GetLineCol(source []byte, offset int) (line, col int) {
|
|
line = 1
|
|
col = 1
|
|
if offset > len(source) {
|
|
offset = len(source)
|
|
}
|
|
for i := 0; i < offset; i++ {
|
|
if source[i] == '\n' {
|
|
line++
|
|
col = 1
|
|
} else {
|
|
col++
|
|
}
|
|
}
|
|
return line, col
|
|
}
|