github.com/icodeface/tls@v0.0.0-20230910023335-34df9250cd12/internal/x/net/idna/trieval.go (about)

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