本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.0KB

  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..14 unused
  27. // 13 mayNeedNorm
  28. // 12..11 attributes
  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. // Attributes
  47. attributesMask = 0x1800
  48. viramaModifier = 0x1800
  49. modifier = 0x1000
  50. rtl = 0x0800
  51. mayNeedNorm = 0x2000
  52. )
  53. // A category corresponds to a category defined in the IDNA mapping table.
  54. type category uint16
  55. const (
  56. unknown category = 0 // not currently defined in unicode.
  57. mapped category = 1
  58. disallowedSTD3Mapped category = 2
  59. deviation category = 3
  60. )
  61. const (
  62. valid category = 0x08
  63. validNV8 category = 0x18
  64. validXV8 category = 0x28
  65. disallowed category = 0x40
  66. disallowedSTD3Valid category = 0x80
  67. ignored category = 0xC0
  68. )
  69. // join types and additional rune information
  70. const (
  71. joiningL = (iota + 1)
  72. joiningD
  73. joiningT
  74. joiningR
  75. //the following types are derived during processing
  76. joinZWJ
  77. joinZWNJ
  78. joinVirama
  79. numJoinTypes
  80. )
  81. func (c info) isMapped() bool {
  82. return c&0x3 != 0
  83. }
  84. func (c info) category() category {
  85. small := c & catSmallMask
  86. if small != 0 {
  87. return category(small)
  88. }
  89. return category(c & catBigMask)
  90. }
  91. func (c info) joinType() info {
  92. if c.isMapped() {
  93. return 0
  94. }
  95. return (c >> joinShift) & joinMask
  96. }
  97. func (c info) isModifier() bool {
  98. return c&(modifier|catSmallMask) == modifier
  99. }
  100. func (c info) isViramaModifier() bool {
  101. return c&(attributesMask|catSmallMask) == viramaModifier
  102. }
上海开阖软件有限公司 沪ICP备12045867号-1