1 // Copyright 2016 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.
7 // appendMapping appends the mapping for the respective rune. isMapped must be
8 // true. A mapping is a categorization of a rune as defined in UTS #46.
9 func (c info) appendMapping(b []byte, s string) []byte {
10 index := int(c >> indexShift)
13 return append(b, s[1:s[0]+1]...)
16 if c&inlineXOR == inlineXOR {
17 // TODO: support and handle two-byte inline masks
18 b[len(b)-1] ^= byte(index)
20 for p := len(b) - int(xorData[index]); p < len(b); p++ {
22 b[p] ^= xorData[index]
28 // Sparse block handling code.
30 type valueRange struct {
31 value uint16 // header: value:stride
32 lo, hi byte // header: lo:n
35 type sparseBlocks struct {
40 var idnaSparse = sparseBlocks{
41 values: idnaSparseValues[:],
42 offset: idnaSparseOffset[:],
45 // Don't use newIdnaTrie to avoid unconditional linking in of the table.
46 var trie = &idnaTrie{}
48 // lookup determines the type of block n and looks up the value for b.
49 // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block
50 // is a list of ranges with an accompanying value. Given a matching range r,
51 // the value for b is by r.value + (b - r.lo) * stride.
52 func (t *sparseBlocks) lookup(n uint32, b byte) uint16 {
54 header := t.values[offset]
56 hi := lo + uint16(header.lo)
60 if r.lo <= b && b <= r.hi {
61 return r.value + uint16(b-r.lo)*header.value