github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/text/currency/gen_common.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build ignore 6 7 package main 8 9 import "golang.org/x/text/language" 10 11 // This file contains code common to gen.go and the package code. 12 13 const ( 14 cashShift = 3 15 roundMask = 0x7 16 ) 17 18 // currencyInfo contains information about a currency. 19 // bits 0..2: index into roundings for standard rounding 20 // bits 3..5: index into roundings for cash rounding 21 type currencyInfo byte 22 23 // roundingType defines the scale (number of fractional decimals) and increments 24 // in terms of units of size 10^-scale. For example, for scale == 2 and 25 // increment == 1, the currency is rounded to units of 0.01. 26 type roundingType struct { 27 scale, increment uint8 28 } 29 30 // roundings contains rounding data for currencies. This struct is 31 // created by hand as it is very unlikely to change much. 32 var roundings = [...]roundingType{ 33 {2, 1}, // default 34 {0, 1}, 35 {1, 1}, 36 {3, 1}, 37 {4, 1}, 38 {2, 5}, // cash rounding alternative 39 } 40 41 // regionToCode returns a 16-bit region code. Only two-letter codes are 42 // supported. (Three-letter codes are not needed.) 43 func regionToCode(r language.Region) uint16 { 44 if s := r.String(); len(s) == 2 { 45 return uint16(s[0])<<8 | uint16(s[1]) 46 } 47 return 0 48 }