Initial check-in

This commit is contained in:
Ray Miller 2023-10-07 17:12:47 +01:00
commit 334eb5f4d0
11 changed files with 1014 additions and 0 deletions

38
util/util.go Normal file
View file

@ -0,0 +1,38 @@
package util
import (
"bytes"
"strings"
"unicode"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
func Normalize(s string) []byte {
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
s, _, _ = transform.String(t, s)
s = strings.ToLower(s)
return []byte(s)
}
func LowerCaseAlpha(s string) []byte {
result := bytes.NewBuffer(nil)
for _, x := range Normalize(s) {
if x >= 'a' && x <= 'z' {
result.WriteByte(x)
}
}
return result.Bytes()
}
func LowerCaseAlphaOrDot(s string) []byte {
result := bytes.NewBuffer(nil)
for _, x := range Normalize(s) {
if x >= 'a' && x <= 'z' || x == '.' {
result.WriteByte(x)
}
}
return result.Bytes()
}