Created
February 18, 2020 11:58
-
-
Save slav123/848fdbcf162643ddb6c27d43644648d3 to your computer and use it in GitHub Desktop.
text normalization in golang (remove accents from string_
This file contains hidden or 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
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