mirror of
https://github.com/EnumeratedDev/typer.git
synced 2026-09-21 07:36:11 +00:00
Use rune arrays instead of go strings for UTF-8 support
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user