1 // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
5 // This file contains definitions for interpreting the trie value of the case
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.
10 // info holds case information for a single rune. It is the value returned
11 // by a trie lookup. Most mapping information can be stored in a single 16-bit
12 // value. If not, for example when a rune is mapped to multiple runes, the value
13 // stores some basic case data and an index into an array with additional data.
15 // The per-rune values have the following format:
18 // 15..5 unsigned exception index
21 // 15..8 XOR pattern or index to XOR pattern for case mapping
22 // Only 13..8 are used for XOR patterns.
23 // 7 inverseFold (fold to upper, not to lower)
24 // 6 index: interpret the XOR pattern as an index
25 // or isMid if case mode is cIgnorableUncased.
26 // 5..4 CCC: zero (normal or break), above or other
28 // 3 exception: interpret this value as an exception index
29 // (TODO: is this bit necessary? Probably implied from case mode.)
32 // For the non-exceptional cases, a rune must be either uncased, lowercase or
33 // uppercase. If the rune is cased, the XOR pattern maps either a lowercase
34 // rune to uppercase or an uppercase rune to lowercase (applied to the 10
35 // least-significant bits of the rune).
37 // See the definitions below for a more detailed description of the various
43 fullCasedMask = 0x0007
44 ignorableMask = 0x0006
45 ignorableValue = 0x0004
47 inverseFoldBit = 1 << 7
57 // There is no mapping if all xor bits and the exception bit are zero.
58 hasMappingMask = 0xff80 | exceptionBit
61 // The case mode bits encodes the case type of a rune. This includes uncased,
62 // title, upper and lower case and case ignorable. (For a definition of these
63 // terms see Chapter 3 of The Unicode Standard Core Specification.) In some rare
64 // cases, a rune can be both cased and case-ignorable. This is encoded by
65 // cIgnorableCased. A rune of this type is always lower case. Some runes are
66 // cased while not having a mapping.
68 // A common pattern for scripts in the Unicode standard is for upper and lower
69 // case runes to alternate for increasing rune values (e.g. the accented Latin
70 // ranges starting from U+0100 and U+1E00 among others and some Cyrillic
71 // characters). We use this property by defining a cXORCase mode, where the case
72 // mode (always upper or lower case) is derived from the rune value. As the XOR
73 // pattern for case mappings is often identical for successive runes, using
74 // cXORCase can result in large series of identical trie values. This, in turn,
75 // allows us to better compress the trie blocks.
77 cUncased info = iota // 000
81 cIgnorableUncased // 100
82 cIgnorableCased // 101 // lower case if mappings exist
83 cXORCase // 11x // case is cLower | ((rune&1) ^ x)
88 func (c info) isCased() bool {
89 return c&casedMask != 0
92 func (c info) isCaseIgnorable() bool {
93 return c&ignorableMask == ignorableValue
96 func (c info) isNotCasedAndNotCaseIgnorable() bool {
97 return c&fullCasedMask == 0
100 func (c info) isCaseIgnorableAndNotCased() bool {
101 return c&fullCasedMask == cIgnorableUncased
104 func (c info) isMid() bool {
105 return c&(fullCasedMask|isMidBit) == isMidBit|cIgnorableUncased
108 // The case mapping implementation will need to know about various Canonical
109 // Combining Class (CCC) values. We encode two of these in the trie value:
110 // cccZero (0) and cccAbove (230). If the value is cccOther, it means that
111 // CCC(r) > 0, but not 230. A value of cccBreak means that CCC(r) == 0 and that
112 // the rune also has the break category Break (see below).
114 cccBreak info = iota << 4
119 cccMask = cccBreak | cccZero | cccAbove | cccOther
128 // The exceptions slice holds data that does not fit in a normal info entry.
129 // The entry is pointed to by the exception index in an entry. It has the
135 // 5..4 CCC type (same bits as entry)
137 // 2..0 length of fold
141 // 5..3 length of 1st mapping of case type
142 // 2..0 length of 2nd mapping of case type
145 // lower -> upper, title
146 // upper -> lower, title
147 // title -> lower, upper
149 // Lengths with the value 0x7 indicate no value and implies no change.
150 // A length of 0 indicates a mapping to zero-length string.
153 // case folding bytes
154 // lowercase mapping bytes
155 // uppercase mapping bytes
156 // titlecase mapping bytes
157 // closure mapping bytes (for NFKC_Casefold). (TODO)
160 // missing fold -> lower
161 // missing title -> upper
162 // all missing -> original rune
164 // exceptions starts with a dummy byte to enforce that there is no zero index
172 // References to generated trie.
174 var trie = newCaseTrie(0)
176 var sparse = sparseBlocks{
177 values: sparseValues[:],
178 offsets: sparseOffsets[:],
181 // Sparse block lookup code.
183 // valueRange is an entry in a sparse block.
184 type valueRange struct {
189 type sparseBlocks struct {
194 // lookup returns the value from values block n for byte b using binary search.
195 func (s *sparseBlocks) lookup(n uint32, b byte) uint16 {
201 if r.lo <= b && b <= r.hi {
213 // lastRuneForTesting is the last rune used for testing. Everything after this
215 const lastRuneForTesting = rune(0x1FFFF)