utf 8 - Golang: How to correctly parse UTF-8 string from C -
i'm newbie go world, maybe obvious.
i have go function i'm exposing c go build -buildmode=c-shared , corresponding //export funcname comment. (you can see here: https://github.com/udl/bmatch/blob/master/ext/levenshtein.go#l42)
my conversion works this:
func distance(s1in, s2in *c.char) int { s1 := c.gostring(s1in) s2 := c.gostring(s2in) how handle utf-8 input here? i've seen there utf-8 package don't quite how works. https://golang.org/pkg/unicode/utf8/
thank you!
you don't need special. utf-8 go's "native" character encoding, can use functions utf8 package mentioned, e.g. utf8.runecountinstring number of unicode runes in string. keep in mind len(s) still return number of bytes in string.
see this post in official blog or this article details.
Comments
Post a Comment