const maxCoreSize … const max99thPercentileSize … const maxSimpleUExtensionSize … type Tag … // Make is a convenience wrapper for Parse that omits the error. // In case of an error, a sensible default is returned. func Make(s string) Tag { … } // Raw returns the raw base language, script and region, without making an // attempt to infer their values. // TODO: consider removing func (t Tag) Raw() (b Language, s Script, r Region) { … } // equalTags compares language, script and region subtags only. func (t Tag) equalTags(a Tag) bool { … } // IsRoot returns true if t is equal to language "und". func (t Tag) IsRoot() bool { … } // IsPrivateUse reports whether the Tag consists solely of an IsPrivateUse use // tag. func (t Tag) IsPrivateUse() bool { … } // RemakeString is used to update t.str in case lang, script or region changed. // It is assumed that pExt and pVariant still point to the start of the // respective parts. func (t *Tag) RemakeString() { … } // genCoreBytes writes a string for the base languages, script and region tags // to the given buffer and returns the number of bytes written. It will never // write more than maxCoreSize bytes. func (t *Tag) genCoreBytes(buf []byte) int { … } // String returns the canonical string representation of the language tag. func (t Tag) String() string { … } // MarshalText implements encoding.TextMarshaler. func (t Tag) MarshalText() (text []byte, err error) { … } // UnmarshalText implements encoding.TextUnmarshaler. func (t *Tag) UnmarshalText(text []byte) error { … } // Variants returns the part of the tag holding all variants or the empty string // if there are no variants defined. func (t Tag) Variants() string { … } // VariantOrPrivateUseTags returns variants or private use tags. func (t Tag) VariantOrPrivateUseTags() string { … } // HasString reports whether this tag defines more than just the raw // components. func (t Tag) HasString() bool { … } // Parent returns the CLDR parent of t. In CLDR, missing fields in data for a // specific language are substituted with fields from the parent language. // The parent for a language may change for newer versions of CLDR. func (t Tag) Parent() Tag { … } // ParseExtension parses s as an extension and returns it on success. func ParseExtension(s string) (ext string, err error) { … } // HasVariants reports whether t has variants. func (t Tag) HasVariants() bool { … } // HasExtensions reports whether t has extensions. func (t Tag) HasExtensions() bool { … } // Extension returns the extension of type x for tag t. It will return // false for ok if t does not have the requested extension. The returned // extension will be invalid in this case. func (t Tag) Extension(x byte) (ext string, ok bool) { … } // Extensions returns all extensions of t. func (t Tag) Extensions() []string { … } // TypeForKey returns the type associated with the given key, where key and type // are of the allowed values defined for the Unicode locale extension ('u') in // https://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers. // TypeForKey will traverse the inheritance chain to get the correct value. // // If there are multiple types associated with a key, only the first will be // returned. If there is no type associated with a key, it returns the empty // string. func (t Tag) TypeForKey(key string) string { … } var errPrivateUse … var errInvalidArguments … // SetTypeForKey returns a new Tag with the key set to type, where key and type // are of the allowed values defined for the Unicode locale extension ('u') in // https://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers. // An empty value removes an existing pair with the same key. func (t Tag) SetTypeForKey(key, value string) (Tag, error) { … } // findTypeForKey returns the start and end position for the type corresponding // to key or the point at which to insert the key-value pair if the type // wasn't found. The hasExt return value reports whether an -u extension was present. // Note: the extensions are typically very small and are likely to contain // only one key-type pair. func (t Tag) findTypeForKey(key string) (start, sep, end int, hasExt bool) { … } // ParseBase parses a 2- or 3-letter ISO 639 code. // It returns a ValueError if s is a well-formed but unknown language identifier // or another error if another error occurred. func ParseBase(s string) (l Language, err error) { … } // ParseScript parses a 4-letter ISO 15924 code. // It returns a ValueError if s is a well-formed but unknown script identifier // or another error if another error occurred. func ParseScript(s string) (scr Script, err error) { … } // EncodeM49 returns the Region for the given UN M.49 code. // It returns an error if r is not a valid code. func EncodeM49(r int) (Region, error) { … } // ParseRegion parses a 2- or 3-letter ISO 3166-1 or a UN M.49 code. // It returns a ValueError if s is a well-formed but unknown region identifier // or another error if another error occurred. func ParseRegion(s string) (r Region, err error) { … } // IsCountry returns whether this region is a country or autonomous area. This // includes non-standard definitions from CLDR. func (r Region) IsCountry() bool { … } // IsGroup returns whether this region defines a collection of regions. This // includes non-standard definitions from CLDR. func (r Region) IsGroup() bool { … } // Contains returns whether Region c is contained by Region r. It returns true // if c == r. func (r Region) Contains(c Region) bool { … } var errNoTLD … // TLD returns the country code top-level domain (ccTLD). UK is returned for GB. // In all other cases it returns either the region itself or an error. // // This method may return an error for a region for which there exists a // canonical form with a ccTLD. To get that ccTLD canonicalize r first. The // region will already be canonicalized it was obtained from a Tag that was // obtained using any of the default methods. func (r Region) TLD() (Region, error) { … } // Canonicalize returns the region or a possible replacement if the region is // deprecated. It will not return a replacement for deprecated regions that // are split into multiple regions. func (r Region) Canonicalize() Region { … } type Variant … // ParseVariant parses and returns a Variant. An error is returned if s is not // a valid variant. func ParseVariant(s string) (v Variant, err error) { … } // String returns the string representation of the variant. func (v Variant) String() string { … }