MCPcopy Create free account
hub / github.com/cherish-chat/xxim-server / FirstUtf8

Method FirstUtf8

common/utils/string.go:10–21  ·  view source on GitHub ↗

FirstUtf8 获取字符串的第一个utf8字符,如果字符串为空,则返回” 如果字符串不是ascii编码,则返回第一个utf8字符,如果是ascii编码,则返回第一个字符

(s string)

Source from the content-addressed store, hash-verified

8// FirstUtf8 获取字符串的第一个utf8字符,如果字符串为空,则返回”
9// 如果字符串不是ascii编码,则返回第一个utf8字符,如果是ascii编码,则返回第一个字符
10func (x *xString) FirstUtf8(s string) string {
11 if len(s) == 0 {
12 return ""
13 }
14 if s[0] < 128 {
15 return s[0:1]
16 } else if len(s) >= 3 {
17 return s[0:3]
18 } else {
19 return s
20 }
21}
22
23func (x *xString) Utf8Split(s string, length int) string {
24 if len(s) == 0 {

Callers 2

Test_xString_FirstUtf8Function · 0.95
Utf8SplitMethod · 0.95

Calls

no outgoing calls

Tested by 1

Test_xString_FirstUtf8Function · 0.76