github.com/unidoc/unidoc@v2.2.0+incompatible/pdf/internal/cmap/utils.go (about)

     1  /*
     2   * This file is subject to the terms and conditions defined in
     3   * file 'LICENSE.md', which is part of this source code package.
     4   */
     5  
     6  package cmap
     7  
     8  import "bytes"
     9  
    10  func hexToUint64(shex cmapHexString) uint64 {
    11  	val := uint64(0)
    12  
    13  	for _, v := range shex.b {
    14  		val <<= 8
    15  		val |= uint64(v)
    16  	}
    17  
    18  	return val
    19  }
    20  
    21  func hexToString(shex cmapHexString) string {
    22  	var buf bytes.Buffer
    23  
    24  	// Assumes unicode in format <HHLL> with 2 bytes HH and LL representing a rune.
    25  	for i := 0; i < len(shex.b)-1; i += 2 {
    26  		b1 := uint64(shex.b[i])
    27  		b2 := uint64(shex.b[i+1])
    28  		r := rune((b1 << 8) | b2)
    29  
    30  		buf.WriteRune(r)
    31  	}
    32  
    33  	return buf.String()
    34  }