trieval.go 3.0 KB

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