Documentation
¶
Overview ¶
Package country provides a data type for ISO-3166, and a list of countries from Unicode CLDR.
Example ¶
package main import ( "fmt" "github.com/blueboardio/cldr/v2/country" ) func main() { FR := country.Code("FR") fmt.Println(FR.Emoji(), country.Countries[FR].Name) }
Output: 🇫🇷 France
Index ¶
- Variables
- type Code
- func (cc Code) Emoji() string
- func (cc Code) EmojiRunes() (rune, rune)
- func (cc Code) IsValid() bool
- func (cc Code) MarshalText() ([]byte, error)
- func (cc *Code) Scan(src interface{}) error
- func (cc *Code) Set(src string) error
- func (cc Code) String() string
- func (cc *Code) UnmarshalText(src []byte) error
- func (cc Code) Value() (driver.Value, error)
- type Emoji
- 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) Currencies() currency.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)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Countries = map[Code]*Info{}/* 260 elements not displayed */
Countries is the list of countries from Unicode CLDR.
Source: cldr-common-45.0.zip
The following codes are removed:
QO (duplicate of UM) ZZ (unknown)
var ErrInvalidCountryCode = errors.New("invalid country code")
var ErrInvalidSet = errors.New("invalid countries set")
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code string
Code represents an ISO 3166 country code: 2 ASCII letters, uppercase. See https://www.iso.org/fr/iso-3166-country-codes.html.
func (Code) Emoji ¶
Emoji converts "FR" to "🇫🇷".
Example ¶
package main import ( "fmt" "github.com/blueboardio/cldr/v2/country" ) func main() { fmt.Println(country.Code("FR").Emoji()) }
Output: 🇫🇷
func (Code) EmojiRunes ¶ added in v2.2.0
EmojiRunes returns the 2 runes that represents the emoji for the country code.
func (Code) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Code) Set ¶
Set implements flag.Value.
Set accepts both "FR" and "🇫🇷" (emoji flag).
Example ¶
package main import ( "fmt" "github.com/blueboardio/cldr/v2/country" ) var reservedCodes []string func init() { reservedCodes = []string{"AA", "ZZ"} c := [2]byte{} cs := c[:] c[0] = 'Q' for b := byte('M'); b <= 'Z'; b++ { c[1] = b reservedCodes = append(reservedCodes, string(cs)) } c[0] = 'X' for b := byte('A'); b <= 'Z'; b++ { if b == 'K' { continue } c[1] = b reservedCodes = append(reservedCodes, string(cs)) } } func main() { var cc country.Code _ = cc.Set("🇫🇷") fmt.Println(cc) _ = cc.Set("GB") fmt.Println(cc.Emoji()) }
Output: FR 🇬🇧
func (*Code) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Emoji ¶
type Emoji struct {
Code
}
Emoji wraps a country Code to have an external representation as a flag emoji.
"FR" => "🇫🇷"
func (Emoji) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (Emoji) Runes ¶ added in v2.2.0
Runes returns the 2 runes that represents the emoji for the country code.
func (Emoji) String ¶
String implements fmt.Stringer.
Example ¶
package main import ( "fmt" "github.com/blueboardio/cldr/v2/country" ) func main() { fmt.Println(country.Emoji{"FR"}.Emoji()) }
Output: 🇫🇷
func (*Emoji) UnmarshalText ¶
UnmarshalText forbids the use of Emoji as an encoding.TextUnmarshaler.
type Set ¶
type Set []Code
Set represents a set of country codes. A set can be used to match a country code against the set. The zero value (nil) matches any country.
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) Currencies ¶
Currencies returns the set of currencies of the countries set.
func (*Set) Filter ¶
Filter removes countries that are not Matched by filter.
The filter is assumed to not contain duplicates. An nil 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 country.
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.