1
2
3
4
5
6
7 package idna
8
9
10
11 func (c info) appendMapping(b []byte, s string) []byte {
12 index := int(c >> indexShift)
13 if c&xorBit == 0 {
14 s := mappings[index:]
15 return append(b, s[1:s[0]+1]...)
16 }
17 b = append(b, s...)
18 if c&inlineXOR == inlineXOR {
19
20 b[len(b)-1] ^= byte(index)
21 } else {
22 for p := len(b) - int(xorData[index]); p < len(b); p++ {
23 index++
24 b[p] ^= xorData[index]
25 }
26 }
27 return b
28 }
29
30
31
32 type valueRange struct {
33 value uint16
34 lo, hi byte
35 }
36
37 type sparseBlocks struct {
38 values []valueRange
39 offset []uint16
40 }
41
42 var idnaSparse = sparseBlocks{
43 values: idnaSparseValues[:],
44 offset: idnaSparseOffset[:],
45 }
46
47
48 var trie = &idnaTrie{}
49
50
51
52
53
54 func (t *sparseBlocks) lookup(n uint32, b byte) uint16 {
55 offset := t.offset[n]
56 header := t.values[offset]
57 lo := offset + 1
58 hi := lo + uint16(header.lo)
59 for lo < hi {
60 m := lo + (hi-lo)/2
61 r := t.values[m]
62 if r.lo <= b && b <= r.hi {
63 return r.value + uint16(b-r.lo)*header.value
64 }
65 if b < r.lo {
66 hi = m
67 } else {
68 lo = m + 1
69 }
70 }
71 return 0
72 }
73
View as plain text