我是围棋世界的新手,所以也许这很明显。
我有一个Go函数,我将使用go build -buildmode=c-shared
和相应的//export funcName
注释将其公开给C。
(您可以在这里看到它:https://github.com/udl/bmatch/blob/master/ext/levenshtein.go#L42)
我的转换当前的工作方式如下:
func distance(s1in, s2in *C.char) int {
s1 := C.GoString(s1in)
s2 := C.GoString(s2in)
我在这里如何处理UTF-8输入?
我已经看到有一个UTF-8软件包,但我不太了解它是如何工作的。 https://golang.org/pkg/unicode/utf8/
谢谢!
最佳答案
您不需要做任何特别的事情。 UTF-8是Go的“ native ”字符编码,因此您可以使用提到的utf8
包中的函数,例如utf8.RuneCountInString
获取字符串中Unicode rune 的数量。请记住,len(s)
仍将返回字符串中的字节数。
有关详细信息,请参见this post in the official blog或this article。
关于c - Golang : How to correctly parse UTF-8 string from C,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32870736/