+// Convert byte array to rune array
+func toRunes(b []byte) []rune {
+ runes := make([]rune, 0, utf8.RuneCount(b))
+
+ for len(b) > 0 {
+ r, size := utf8.DecodeRune(b)
+ runes = append(runes, r)
+
+ b = b[size:]
+ }
+
+ return runes
+}
+
+func sliceStart(slc []byte, index int) []byte {
+ len := len(slc)
+ i := 0
+ totalSize := 0
+ for totalSize < len {
+ if i >= index {
+ return slc[totalSize:]
+ }
+
+ _, size := utf8.DecodeRune(slc[totalSize:])
+ totalSize += size
+ i++
+ }
+
+ return slc[totalSize:]
+}
+
+func sliceEnd(slc []byte, index int) []byte {
+ len := len(slc)
+ i := 0
+ totalSize := 0
+ for totalSize < len {
+ if i >= index {
+ return slc[:totalSize]
+ }
+
+ _, size := utf8.DecodeRune(slc[totalSize:])
+ totalSize += size
+ i++
+ }
+
+ return slc[:totalSize]
+}
+
+// NumOccurrences counts the number of occurrences of a byte in a string