MCPcopy Create free account
hub / github.com/golang/mobile / UTF16Encode

Function UTF16Encode

bind/seq/string.go:30–49  ·  view source on GitHub ↗

UTF16Encode utf16 encodes s into chars. It returns the resulting length in units of uint16. It is assumed that the chars slice has enough room for the encoded string.

(s string, chars []uint16)

Source from the content-addressed store, hash-verified

28// length in units of uint16. It is assumed that the chars slice
29// has enough room for the encoded string.
30func UTF16Encode(s string, chars []uint16) int {
31 n := 0
32 for _, v := range s {
33 switch {
34 case v < 0, surr1 <= v && v < surr3, v > maxRune:
35 v = replacementChar
36 fallthrough
37 case v < surrSelf:
38 chars[n] = uint16(v)
39 n += 1
40 default:
41 // surrogate pair, two uint16 values
42 r1, r2 := utf16.EncodeRune(v)
43 chars[n] = uint16(r1)
44 chars[n+1] = uint16(r2)
45 n += 2
46 }
47 }
48 return n
49}

Callers 1

TestStringFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestStringFunction · 0.68