Finds the byte index of the nth rune in a byte slice
(n int, txt []byte)
| 12 | |
| 13 | // Finds the byte index of the nth rune in a byte slice |
| 14 | func 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 |
| 36 | type searchState struct { |
no test coverage detected