Debian Codegraph @

bind/seq/string.go

raw symbols SCIP
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package seqscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/
6
7 import "unicode/utf16scip-go gomod github.com/golang/go/src go1.24.0 `unicode/utf16`/"
8
9 // Based heavily on package unicode/utf16 from the Go standard library.
10
11 const (
12 replacementCharscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/replacementChar. = '\uFFFD' // Unicode replacement character
13 maxRunescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/maxRune. = '\U0010FFFF' // Maximum valid Unicode code point.
14 )
15
16 const (
17 // 0xd800-0xdc00 encodes the high 10 bits of a pair.
18 // 0xdc00-0xe000 encodes the low 10 bits of a pair.
19 // the value is those 20 bits plus 0x10000.
20 surr1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/surr1. = 0xd800
21 surr2scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/surr2. = 0xdc00
22 surr3scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/surr3. = 0xe000
23
24 surrSelfscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/surrSelf. = 0x10000
25 )
26
27 // UTF16Encode utf16 encodes s into chars. It returns the resulting
28 // length in units of uint16. It is assumed that the chars slice
29 // has enough room for the encoded string.
30 func UTF16Encodescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/UTF16Encode().(s string, chars []uint16) int {
31 n := 0
32 for _, v := range s {
33 switch {
34 case v < 0, surr1scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/surr1. <= v && v < surr3scip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/surr3., v > maxRunescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/maxRune.:
35 v = replacementCharscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/replacementChar.
36 fallthrough
37 case v < surrSelfscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/bind/seq`/surrSelf.:
38 chars[n] = uint16(v)
39 n += 1
40 default:
41 // surrogate pair, two uint16 values
42 r1, r2 := utf16scip-go gomod github.com/golang/go/src go1.24.0 `unicode/utf16`/.EncodeRunescip-go gomod github.com/golang/go/src go1.24.0 `unicode/utf16`/EncodeRune().(v)
43 chars[n] = uint16(r1)
44 chars[n+1] = uint16(r2)
45 n += 2
46 }
47 }
48 return n
49 }