currency

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2019 License: MIT Imports: 4 Imported by: 0

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

View Source
const (
	// Maximum cash fraction digits of any ActiveCurrencies
	MaxFractionCashDigits = 3
)

Variables

View Source
var ActiveCurrencies = map[Code]*Info{}/* 155 elements not displayed */

ActiveCurrencies is the list of current legal tender currencies from Unicode CLDR.

Source: cldr-common-34.0.zip See https://unicode.org/cldr/charts/33/supplemental/detailed_territory_currency_information.html.

View Source
var ErrInvalidCurrencyCode = errors.New("invalid currency code")
View Source
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) IsValid

func (cc Code) IsValid() bool

IsValid returns false if the code is invalid.

func (Code) MarshalText

func (cc Code) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Code) Scan

func (cc *Code) Scan(src interface{}) error

Scan implements database/sql.Scanner.

func (*Code) Set

func (cc *Code) Set(src string) error

Set implements flag.Value.

func (Code) String

func (cc Code) String() string

String implements fmt.Stringer.

func (*Code) UnmarshalText

func (cc *Code) UnmarshalText(src []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Code) Value

func (cc Code) Value() (driver.Value, error)

Value implements database/sql/driver.Valuer.

type FractionInfo

type FractionInfo struct {
	Digits       uint
	Rounding     uint
	CashDigits   uint
	CashRounding uint
}

type Info

type Info struct {
	Code Code

	Fraction FractionInfo

	Countries []string
}

type Set added in v1.2.0

type Set []Code

Set represents a set of currency codes.

The JSON representation (MarshalJSON) is an array of strings. 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) Contains added in v1.2.0

func (cs Set) Contains(c Code) bool

Contains returns true if cs contains c.

func (*Set) Filter added in v1.2.0

func (cs *Set) Filter(filter Set)

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 added in v1.2.0

func (cs Set) HasDuplicates() bool

HasDuplicates checks if cs contains duplicates.

func (Set) Len added in v1.2.0

func (cs Set) Len() int

Len implements sort.Interface.

func (Set) Less added in v1.2.0

func (cs Set) Less(i, j int) bool

Less implements sort.Interface.

func (Set) MarshalJSON added in v1.2.0

func (cs Set) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler.

func (Set) MarshalText added in v1.2.0

func (cs Set) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Set) Matches added in v1.2.0

func (cs Set) Matches(c Code) bool

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 added in v1.2.0

func (cs Set) MatchesAny() bool

MatchesAny returns true if the set is empty.

func (*Set) Remove added in v1.2.0

func (cs *Set) Remove(exclude Set)

Remove removes from cs the intersection of the two sets. If exclude is empty nothing is removed. Order is preserved.

func (*Set) RemoveDuplicates added in v1.2.0

func (cs *Set) RemoveDuplicates()

RemoveDuplicates remove duplicates. Order is preserved. In case of a duplicate the first one is kept.

func (*Set) Scan added in v1.2.0

func (cs *Set) Scan(src interface{}) error

func (*Set) Set added in v1.2.0

func (cs *Set) Set(src string) error

Set implements flag.Value.

func (Set) String added in v1.2.0

func (cs Set) String() string

String implements fmt.Stringer.

func (Set) Swap added in v1.2.0

func (cs Set) Swap(i, j int)

Swap implements sort.Interface.

func (*Set) UnmarshalJSON added in v1.2.0

func (cs *Set) UnmarshalJSON(b []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

func (*Set) UnmarshalText added in v1.2.0

func (cs *Set) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Set) Value added in v1.2.0

func (cs Set) Value() (driver.Value, error)

Value() implements database/sql/driver.Valuer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL