Skip to content

Instantly share code, notes, and snippets.

@slav123
Created February 18, 2020 11:58
Show Gist options
  • Save slav123/848fdbcf162643ddb6c27d43644648d3 to your computer and use it in GitHub Desktop.
Save slav123/848fdbcf162643ddb6c27d43644648d3 to your computer and use it in GitHub Desktop.
text normalization in golang (remove accents from string_
package main
import (
"fmt"
"unicode"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
func isMn(r rune) bool {
return unicode.Is(unicode.Mn, r) // Mn: nonspacing marks
}
func main() {
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
result, _, _ := transform.String(t, "žůžo")
fmt.Println(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment