Documentation ¶
Overview ¶
Package currency provides a data type for ISO 4217 currency code and list of world currencies from Unicode CLDR.
See https://www.iso.org/fr/iso-4217-currency-codes.html. See https://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies. See common/supplemental/supplementalData.xml in CLDR data. See https://unicode.org/cldr/charts/33/supplemental/detailed_territory_currency_information.html
Index ¶
- Constants
- Variables
- type Code
- type FractionInfo
- type Info
- type Set
- func (cs *Set) Add(c Code)
- func (cs Set) Contains(c Code) bool
- func (cs Set) Copy() Set
- func (cs *Set) Filter(filter Set)
- func (cs Set) HasDuplicates() bool
- func (cs Set) Len() int
- func (cs Set) Less(i, j int) bool
- func (cs Set) MarshalJSON() ([]byte, error)
- func (cs Set) MarshalText() ([]byte, error)
- func (cs Set) Matches(c Code) bool
- func (cs Set) MatchesAny() bool
- func (cs *Set) Remove(exclude Set)
- func (cs *Set) RemoveDuplicates()
- func (cs *Set) Scan(src interface{}) error
- func (cs *Set) Set(src string) error
- func (cs Set) String() string
- func (cs Set) Swap(i, j int)
- func (cs *Set) UnmarshalJSON(b []byte) error
- func (cs *Set) UnmarshalText(b []byte) error
- func (cs Set) Value() (driver.Value, error)
Constants ¶
const ( // Maximum cash fraction digits of any ActiveCurrencies MaxFractionCashDigits = 3 // Maximum cash divisor of any ActiveCurrencies (10^MaxFractionCashDigits) MaxCashDivisor = 1000 )
Variables ¶
var ActiveCurrencies = map[Code]*Info{}/* 153 elements not displayed */
ActiveCurrencies is the list of current legal tender currencies from Unicode CLDR.
Source: cldr-common-45.0.zip See https://unicode.org/cldr/charts/33/supplemental/detailed_territory_currency_information.html.
var ErrInvalidCurrencyCode = errors.New("invalid currency code")
var ErrInvalidSet = errors.New("invalid currencies set")
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code string
Code represents an ISO 4217 currency code: 3 ASCII letters, uppercase. See https://www.iso.org/fr/iso-4217-currency-codes.html.
func (Code) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Code) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type FractionInfo ¶
type Info ¶
type Info struct { Code Code Fraction FractionInfo Countries []string }
type Set ¶
type Set []Code
Set represents a set of currency codes. The zero value (nil) matches any currency.
The JSON representation (MarshalJSON) is an array of strings or null. The text representation (MarshalText) is codes separated by comma. The string representation (.String) is the text representation but with "*" if the set is empty.
func (*Set) Filter ¶
Filter removes countries that are not Matched by filter.
The filter is assumed to not contain duplicates. An empty filter is a no-op (matches anything). Order is preserved.
func (Set) HasDuplicates ¶
HasDuplicates checks if cs contains duplicates.
func (Set) MarshalJSON ¶
MarshalJSON implements encoding/json.Marshaler.
func (Set) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (Set) Matches ¶
Matches returns true if the set is empty (matches anything) or contains c.
Same as Contains except for the empty set case which return true for any currency.
func (Set) MatchesAny ¶
MatchesAny returns true if the set is empty.
func (*Set) Remove ¶
Remove removes from cs the intersection of the two sets. If exclude is empty nothing is removed. Order is preserved.
func (*Set) RemoveDuplicates ¶
func (cs *Set) RemoveDuplicates()
RemoveDuplicates remove duplicates. Order is preserved. In case of a duplicate the first one is kept.
func (*Set) UnmarshalJSON ¶
UnmarshalJSON implements encoding/json.Unmarshaler.
func (*Set) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.