github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/text/currency/common.go (about)

     1  // This file was generated by go generate; DO NOT EDIT
     2  
     3  package currency
     4  
     5  import "golang.org/x/text/language"
     6  
     7  // This file contains code common to gen.go and the package code.
     8  
     9  const (
    10  	cashShift = 3
    11  	roundMask = 0x7
    12  )
    13  
    14  // currencyInfo contains information about a currency.
    15  // bits 0..2: index into roundings for standard rounding
    16  // bits 3..5: index into roundings for cash rounding
    17  type currencyInfo byte
    18  
    19  // roundingType defines the scale (number of fractional decimals) and increments
    20  // in terms of units of size 10^-scale. For example, for scale == 2 and
    21  // increment == 1, the currency is rounded to units of 0.01.
    22  type roundingType struct {
    23  	scale, increment uint8
    24  }
    25  
    26  // roundings contains rounding data for currencies. This struct is
    27  // created by hand as it is very unlikely to change much.
    28  var roundings = [...]roundingType{
    29  	{2, 1}, // default
    30  	{0, 1},
    31  	{1, 1},
    32  	{3, 1},
    33  	{4, 1},
    34  	{2, 5}, // cash rounding alternative
    35  }
    36  
    37  // regionToCode returns a 16-bit region code. Only two-letter codes are
    38  // supported. (Three-letter codes are not needed.)
    39  func regionToCode(r language.Region) uint16 {
    40  	if s := r.String(); len(s) == 2 {
    41  		return uint16(s[0])<<8 | uint16(s[1])
    42  	}
    43  	return 0
    44  }