vendor/golang.org/x/text/unicode/norm/forminfo.go
changeset 251 1c52a0eeb952
parent 242 2a9ec03fe5a1
child 265 05c40b36d3b2
equal deleted inserted replaced
250:c040f992052f 251:1c52a0eeb952
     1 // Copyright 2011 The Go Authors. All rights reserved.
     1 // Copyright 2011 The Go Authors. All rights reserved.
     2 // Use of this source code is governed by a BSD-style
     2 // Use of this source code is governed by a BSD-style
     3 // license that can be found in the LICENSE file.
     3 // license that can be found in the LICENSE file.
     4 
     4 
     5 package norm
     5 package norm
       
     6 
       
     7 import "encoding/binary"
     6 
     8 
     7 // This file contains Form-specific logic and wrappers for data in tables.go.
     9 // This file contains Form-specific logic and wrappers for data in tables.go.
     8 
    10 
     9 // Rune info is stored in a separate trie per composing form. A composing form
    11 // Rune info is stored in a separate trie per composing form. A composing form
    10 // and its corresponding decomposing form share the same trie.  Each trie maps
    12 // and its corresponding decomposing form share the same trie.  Each trie maps
   176 // If there is no decomposition, TrailCCC equals CCC.
   178 // If there is no decomposition, TrailCCC equals CCC.
   177 func (p Properties) TrailCCC() uint8 {
   179 func (p Properties) TrailCCC() uint8 {
   178 	return ccc[p.tccc]
   180 	return ccc[p.tccc]
   179 }
   181 }
   180 
   182 
       
   183 func buildRecompMap() {
       
   184 	recompMap = make(map[uint32]rune, len(recompMapPacked)/8)
       
   185 	var buf [8]byte
       
   186 	for i := 0; i < len(recompMapPacked); i += 8 {
       
   187 		copy(buf[:], recompMapPacked[i:i+8])
       
   188 		key := binary.BigEndian.Uint32(buf[:4])
       
   189 		val := binary.BigEndian.Uint32(buf[4:])
       
   190 		recompMap[key] = rune(val)
       
   191 	}
       
   192 }
       
   193 
   181 // Recomposition
   194 // Recomposition
   182 // We use 32-bit keys instead of 64-bit for the two codepoint keys.
   195 // We use 32-bit keys instead of 64-bit for the two codepoint keys.
   183 // This clips off the bits of three entries, but we know this will not
   196 // This clips off the bits of three entries, but we know this will not
   184 // result in a collision. In the unlikely event that changes to
   197 // result in a collision. In the unlikely event that changes to
   185 // UnicodeData.txt introduce collisions, the compiler will catch it.
   198 // UnicodeData.txt introduce collisions, the compiler will catch it.
   186 // Note that the recomposition map for NFC and NFKC are identical.
   199 // Note that the recomposition map for NFC and NFKC are identical.
   187 
   200 
   188 // combine returns the combined rune or 0 if it doesn't exist.
   201 // combine returns the combined rune or 0 if it doesn't exist.
       
   202 //
       
   203 // The caller is responsible for calling
       
   204 // recompMapOnce.Do(buildRecompMap) sometime before this is called.
   189 func combine(a, b rune) rune {
   205 func combine(a, b rune) rune {
   190 	key := uint32(uint16(a))<<16 + uint32(uint16(b))
   206 	key := uint32(uint16(a))<<16 + uint32(uint16(b))
       
   207 	if recompMap == nil {
       
   208 		panic("caller error") // see func comment
       
   209 	}
   191 	return recompMap[key]
   210 	return recompMap[key]
   192 }
   211 }
   193 
   212 
   194 func lookupInfoNFC(b input, i int) Properties {
   213 func lookupInfoNFC(b input, i int) Properties {
   195 	v, sz := b.charinfoNFC(i)
   214 	v, sz := b.charinfoNFC(i)