SliceStart returns a byte slice where the index is a rune index Slices off the end of the slice
(slc []byte, index int)
| 140 | // SliceStart returns a byte slice where the index is a rune index |
| 141 | // Slices off the end of the slice |
| 142 | func SliceStart(slc []byte, index int) []byte { |
| 143 | len := len(slc) |
| 144 | i := 0 |
| 145 | totalSize := 0 |
| 146 | for totalSize < len { |
| 147 | if i >= index { |
| 148 | return slc[:totalSize] |
| 149 | } |
| 150 | |
| 151 | _, _, size := DecodeCharacter(slc[totalSize:]) |
| 152 | totalSize += size |
| 153 | i++ |
| 154 | } |
| 155 | |
| 156 | return slc[:totalSize] |
| 157 | } |
| 158 | |
| 159 | // SliceStartStr is the same as SliceStart but for strings |
| 160 | func SliceStartStr(str string, index int) string { |
no test coverage detected