Documentation
¶
Overview ¶
Package countries holds the phone-number metadata generated from Google's libphonenumber PhoneNumberMetadata.xml.
Metadata values are always used through a *Metadata pointer: they embed sync.Once guards for lazily compiled regular expressions and must not be copied.
Index ¶
Constants ¶
const MaxCallingCodeLen = 3
MaxCallingCodeLen is the length of the longest calling code.
const SourceHash = "20d5582c8eb8e3a291a1499359c6b8e4c5f46610cc5fe04ec5f2c989f812f014"
SourceHash is the SHA-256 of the PhoneNumberMetadata.xml this file was generated from. It identifies exactly which upstream revision of the metadata is baked in, and lets a test confirm the vendored XML and the generated table have not drifted apart.
Variables ¶
var Data = map[string]*Metadata{}/* 245 elements not displayed */
Data maps ISO-3166 alpha-2 region codes to their metadata.
var NonGeo = map[string]*Metadata{
"800": md001_800,
"808": md001_808,
"870": md001_870,
"878": md001_878,
"881": md001_881,
"882": md001_882,
"883": md001_883,
"888": md001_888,
"979": md001_979,
}
NonGeo maps calling codes of non-geographical entities (libphonenumber region "001") to their metadata.
Functions ¶
This section is empty.
Types ¶
type Desc ¶
type Desc struct {
Pattern lazyRe
// Lengths holds the sorted possible national number lengths.
Lengths []int32
// LocalOnly holds lengths that are only valid when dialled locally.
LocalOnly []int32
Example string
}
Desc describes a single number range (fixed line, mobile, toll free, ...).
func (*Desc) HasLocalOnlyLength ¶
HasLocalOnlyLength reports whether n is valid only for local dialling.
type Metadata ¶
type Metadata struct {
ISO2 string
ISO3 string
Name string
// DialCode is the country calling code without a leading '+'.
DialCode string
// IsMainCountry reports whether this region owns DialCode. Several
// regions may share one code (e.g. +1); exactly one is the main region.
IsMainCountry bool
// LeadingDigits disambiguates regions sharing a DialCode.
LeadingDigits lazyRe
NationalPrefix string
// SimpleNationalPrefix is set when the trunk prefix is a plain literal
// with no carrier-code group and no transform rule, which lets the
// parser strip it without the regexp engine.
SimpleNationalPrefix string
// NationalPrefixForParsing matches the trunk prefix (and any carrier
// selection code) to strip before validation.
NationalPrefixForParsing lazyRe
// NationalPrefixTransformRule rewrites the number after stripping.
NationalPrefixTransformRule string
InternationalPrefix lazyRe
PreferredInternationalPrefix string
PreferredExtnPrefix string
MobileNumberPortable bool
// General matches any valid number in the region.
General Desc
// Descs holds the per-type ranges, indexed by PhoneType.
Descs [NumDescs]Desc
// NoIntlDialling matches numbers that cannot be dialled from abroad.
NoIntlDialling Desc
Formats []NumberFormat
// MinLength and MaxLength are the shortest and longest possible national
// number lengths, derived from General.Lengths.
MinLength int
MaxLength int
// Timezones holds the region's IANA time zones. It comes from
// internal/metadata/metadata.json, not from libphonenumber, and is
// empty in the bundled data.
Timezones []string
}
Metadata holds everything known about one calling region.
func RegionsForCode ¶
RegionsForCode returns the metadata of every region sharing the calling code made of the first n digits of digits, main region first. It returns nil when no region uses that code. The lookup performs no allocation.
type NumberFormat ¶
type NumberFormat struct {
// Pattern is anchored and captures the groups referenced by Format.
Pattern lazyRe
// Format is the replacement template using $1..$9.
Format string
// LeadingDigits, when set, must match the start of the national number
// for this rule to apply.
LeadingDigits lazyRe
// NationalPrefixFormattingRule wraps the formatted groups, e.g. "$NP$FG".
NationalPrefixFormattingRule string
// NationalPrefixOptional reports whether the national prefix may be
// omitted when formatting nationally.
NationalPrefixOptional bool
// CarrierCodeFormattingRule wraps the groups when a carrier code is used.
CarrierCodeFormattingRule string
// IntlFormat overrides Format for international formatting. The value
// "NA" means the number must not be formatted internationally.
IntlFormat string
}
NumberFormat is one national formatting rule.
type PhoneType ¶
type PhoneType uint8
PhoneType identifies a number range within a country's metadata.
const ( FixedLine PhoneType = iota Mobile TollFree PremiumRate VoIP PersonalNumber Pager UAN Voicemail // NumDescs is the number of per-type descriptors stored in Metadata.Descs. NumDescs // FixedLineOrMobile is reported when a number matches both ranges. FixedLineOrMobile // Unknown is reported when no range matches. Unknown )