Use rune arrays instead of go strings for UTF-8 support

This commit is contained in:
2026-04-27 15:45:19 +03:00
parent 6a701dd311
commit a1e8d6c19a
5 changed files with 111 additions and 72 deletions
+35
View File
@@ -0,0 +1,35 @@
package runestring
type RuneString []rune
func Split(s RuneString, sep rune) []RuneString {
ret := make([]RuneString, 0)
currentStr := make(RuneString, 0)
for _, r := range s {
if r == sep {
ret = append(ret, currentStr)
currentStr = make(RuneString, 0)
continue
}
currentStr = append(currentStr, r)
}
return ret
}
func Index(s, substr RuneString) int {
substrIndex := 0
for i, r := range s {
if r == substr[substrIndex] {
if substrIndex == len(substr) {
return i - substrIndex
}
substrIndex++
} else {
substrIndex = 0
}
}
return -1
}