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

Function runeToByteIndex

internal/buffer/line_array.go:14–33  ·  view source on GitHub ↗

Finds the byte index of the nth rune in a byte slice

(n int, txt []byte)

Source from the content-addressed store, hash-verified

12
13// Finds the byte index of the nth rune in a byte slice
14func runeToByteIndex(n int, txt []byte) int {
15 if n == 0 {
16 return 0
17 }
18
19 count := 0
20 i := 0
21 for len(txt) > 0 {
22 _, _, size := util.DecodeCharacter(txt)
23
24 txt = txt[size:]
25 count += size
26 i++
27
28 if i == n {
29 break
30 }
31 }
32 return count
33}
34
35// A searchState contains the search match info for a single line
36type searchState struct {

Callers 3

insertMethod · 0.85
removeMethod · 0.85
SubstrMethod · 0.85

Calls 1

DecodeCharacterFunction · 0.92

Tested by

no test coverage detected