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