Created
April 5, 2022 16:03
-
-
Save wrandowR/5e90df8d2a9853e8786349f758f640b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Normalize for golang