Skip to content

Instantly share code, notes, and snippets.

@wrandowR
Created April 5, 2022 16:03
Show Gist options
  • Save wrandowR/5e90df8d2a9853e8786349f758f640b4 to your computer and use it in GitHub Desktop.
Save wrandowR/5e90df8d2a9853e8786349f758f640b4 to your computer and use it in GitHub Desktop.
func Normalize(text string) string {
rgTable := rangetable.Merge(unicode.Mn, unicode.P)
t := transform.Chain(norm.NFD, runes.Remove(runes.In(rgTable)), norm.NFC)
text, _, err := transform.String(t, text)
if err != nil {
log.WithError(err).Error("Error normalizing text")
return internalNormalize(text)
}
return internalNormalize(text)
}
func internalNormalize(text string) string {
text = strings.TrimSpace(text)
text = strings.ToLower(text)
return text
}
@wrandowR
Copy link
Author

wrandowR commented Apr 5, 2022

Normalize for golang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment