utf8.RuneCountInString(字符串变量名)
bytes := []byte(字符串变量名)
for len(bytes) > 0 {
ch, size := utf8.DecodeRune(bytes)
bytes = bytes[size:]
fmt.Printf("%c", ch)
}
for i, ch := range []rune(字符串变量名) {
fmt.Printf("(%d %c", i, ch)
}
func getSuffixDir(filePath string, prefix string) string {
bufferLength := len(prefix)
prefixByte := make([]byte, bufferLength)
var b bytes.Buffer
b.Write([]byte(filePath))
b.Read(prefixByte)
return b.String()
}
func heavy(keywords []string) []string {
var theMap = make(map[string]bool)
var returnList []string
for i := 0;i < len(keywords);i++ {
if _, ok := theMap[keywords[i]]; ok {
continue
} else {
theMap[keywords[i]] = false
returnList = append(returnList, keywords[i])
}
}
return returnList
}
if !validUTF8(file_data) {
keywords = ConvertToString(keywords, "GB18030", "UTF-8")
}
func ConvertToString(src string, srcCode string, tagCode string) string {
srcCoder := mahonia.NewDecoder(srcCode)
srcResult := srcCoder.ConvertString(src)
tagCoder := mahonia.NewDecoder(tagCode)
_, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
result := string(cdata)
return result
}
func validUTF8(buf []byte) bool{
nBytes := 0
for i:= 0;i<len(buf);i++{
if nBytes == 0{
if (buf[i] & 0x80) != 0 {
for (buf[i] & 0x80) != 0 {
buf[i] <<= 1
nBytes++
}
if nBytes < 2 || nBytes > 6 {
return false
}
nBytes--
}
}else{
if buf[i] & 0xc0 != 0x80{
return false
}
nBytes--
}
}
return nBytes == 0
}
返回数据 := "[]"
if !strings.EqualFold(string(json数据), "") {
返回数据 = string(json数据)
}