MCPcopy Index your code
hub / github.com/micro-editor/micro / ByteOffset

Function ByteOffset

internal/buffer/loc.go:139–148  ·  view source on GitHub ↗

ByteOffset is just like ToCharPos except it counts bytes instead of runes

(pos Loc, buf *Buffer)

Source from the content-addressed store, hash-verified

137
138// ByteOffset is just like ToCharPos except it counts bytes instead of runes
139func 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
151func clamp(pos Loc, la *LineArray) Loc {

Callers

nothing calls this directly

Calls 1

LineMethod · 0.80

Tested by

no test coverage detected