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.
9 // This file contains definitions for interpreting the trie value of the idna
10 // trie generated by "go run gen*.go". It is shared by both the generator
11 // program and the resultant package. Sharing is achieved by the generator
12 // copying gen_trieval.go to trieval.go and changing what's above this comment.
14 // info holds information from the IDNA mapping table for a single rune. It is
15 // the value returned by a trie lookup. In most cases, all information fits in
16 // a 16-bit value. For mappings, this value may contain an index into a slice
17 // with the mapped string. Such mappings can consist of the actual mapped value
18 // or an XOR pattern to be applied to the bytes of the UTF8 encoding of the
19 // input rune. This technique is used by the cases packages and reduces the
20 // table size significantly.
22 // The per-rune values have the following format:
26 // 15..13 inline XOR marker
28 // 10..3 inline XOR mask
30 // 15..3 index into xor or mapping table
34 // 12 modifier (including virama)
40 // 1..0 mapped category
42 // See the definitions below for a more detailed description of the various
50 xorBit = 0x4 // interpret the index as an xor pattern
51 inlineXOR = 0xE000 // These bits are set if the XOR pattern is inlined.
56 viramaModifier = 0x0800
60 // A category corresponds to a category defined in the IDNA mapping table.
64 unknown category = 0 // not defined currently in unicode.
66 disallowedSTD3Mapped category = 2
67 deviation category = 3
72 validNV8 category = 0x18
73 validXV8 category = 0x28
74 disallowed category = 0x40
75 disallowedSTD3Valid category = 0x80
76 ignored category = 0xC0
79 // join types and additional rune information
86 //the following types are derived during processing
93 func (c info) isMapped() bool {
97 func (c info) category() category {
98 small := c & catSmallMask
100 return category(small)
102 return category(c & catBigMask)
105 func (c info) joinType() info {
109 return (c >> joinShift) & joinMask
112 func (c info) isModifier() bool {
113 return c&(modifier|catSmallMask) == modifier
116 func (c info) isViramaModifier() bool {
117 return c&(viramaModifier|catSmallMask) == viramaModifier