trieval.go 2.9 KB

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