diff options
Diffstat (limited to 'src/util/util.go')
-rw-r--r-- | src/util/util.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/util.go b/src/util/util.go index a0e12696..eeeb75f4 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -6,6 +6,7 @@ import "C" import ( "os" "time" + "unicode/utf8" ) // Max returns the largest integer @@ -88,3 +89,18 @@ func TrimRight(runes []rune) []rune { } return runes[0 : i+1] } + +func BytesToRunes(bytea []byte) []rune { + runes := make([]rune, 0, len(bytea)) + for i := 0; i < len(bytea); { + if bytea[i] < utf8.RuneSelf { + runes = append(runes, rune(bytea[i])) + i++ + } else { + r, sz := utf8.DecodeRune(bytea[i:]) + i += sz + runes = append(runes, r) + } + } + return runes +} |