...
1
2
3
4
5
6
7 package idna
8
9
10
11 type valueRange struct {
12 value uint16
13 lo, hi byte
14 }
15
16 type sparseBlocks struct {
17 values []valueRange
18 offset []uint16
19 }
20
21 var idnaSparse = sparseBlocks{
22 values: idnaSparseValues[:],
23 offset: idnaSparseOffset[:],
24 }
25
26
27 var trie = &idnaTrie{}
28
29
30
31
32
33 func (t *sparseBlocks) lookup(n uint32, b byte) uint16 {
34 offset := t.offset[n]
35 header := t.values[offset]
36 lo := offset + 1
37 hi := lo + uint16(header.lo)
38 for lo < hi {
39 m := lo + (hi-lo)/2
40 r := t.values[m]
41 if r.lo <= b && b <= r.hi {
42 return r.value + uint16(b-r.lo)*header.value
43 }
44 if b < r.lo {
45 hi = m
46 } else {
47 lo = m + 1
48 }
49 }
50 return 0
51 }
52
View as plain text