1// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
2
3package idna
4
5// This file contains definitions for interpreting the trie value of the idna
6// trie generated by "go run gen*.go". It is shared by both the generator
7// program and the resultant package. Sharing is achieved by the generator
8// copying gen_trieval.go to trieval.go and changing what's above this comment.
9
10// info holds information from the IDNA mapping table for a single rune. It is
11// the value returned by a trie lookup. In most cases, all information fits in
12// a 16-bit value. For mappings, this value may contain an index into a slice
13// with the mapped string. Such mappings can consist of the actual mapped value
14// or an XOR pattern to be applied to the bytes of the UTF8 encoding of the
15// input rune. This technique is used by the cases packages and reduces the
16// table size significantly.
17//
18// The per-rune values have the following format:
19//
20//   if mapped {
21//     if inlinedXOR {
22//       15..13 inline XOR marker
23//       12..11 unused
24//       10..3  inline XOR mask
25//     } else {
26//       15..3  index into xor or mapping table
27//     }
28//   } else {
29//       15..13 unused
30//           12 modifier (including virama)
31//           11 virama modifier
32//       10..8  joining type
33//        7..3  category type
34//   }
35//      2  use xor pattern
36//   1..0  mapped category
37//
38// See the definitions below for a more detailed description of the various
39// bits.
40type info uint16
41
42const (
43	catSmallMask = 0x3
44	catBigMask   = 0xF8
45	indexShift   = 3
46	xorBit       = 0x4    // interpret the index as an xor pattern
47	inlineXOR    = 0xE000 // These bits are set if the XOR pattern is inlined.
48
49	joinShift = 8
50	joinMask  = 0x07
51
52	viramaModifier = 0x0800
53	modifier       = 0x1000
54)
55
56// A category corresponds to a category defined in the IDNA mapping table.
57type category uint16
58
59const (
60	unknown              category = 0 // not defined currently in unicode.
61	mapped               category = 1
62	disallowedSTD3Mapped category = 2
63	deviation            category = 3
64)
65
66const (
67	valid               category = 0x08
68	validNV8            category = 0x18
69	validXV8            category = 0x28
70	disallowed          category = 0x40
71	disallowedSTD3Valid category = 0x80
72	ignored             category = 0xC0
73)
74
75// join types and additional rune information
76const (
77	joiningL = (iota + 1)
78	joiningD
79	joiningT
80	joiningR
81
82	//the following types are derived during processing
83	joinZWJ
84	joinZWNJ
85	joinVirama
86	numJoinTypes
87)
88
89func (c info) isMapped() bool {
90	return c&0x3 != 0
91}
92
93func (c info) category() category {
94	small := c & catSmallMask
95	if small != 0 {
96		return category(small)
97	}
98	return category(c & catBigMask)
99}
100
101func (c info) joinType() info {
102	if c.isMapped() {
103		return 0
104	}
105	return (c >> joinShift) & joinMask
106}
107
108func (c info) isModifier() bool {
109	return c&(modifier|catSmallMask) == modifier
110}
111
112func (c info) isViramaModifier() bool {
113	return c&(viramaModifier|catSmallMask) == viramaModifier
114}
115