Source File
language.go
Belonging Package
golang.org/x/text/internal/language
package language // import "golang.org/x/text/internal/language"
import (
)
maxCoreSize = 12
maxSimpleUExtensionSize = 14
)
func ( *Tag) () {
if .str == "" {
return
}
:= .str[.pVariant:]
if .pVariant > 0 {
= [1:]
}
if .equalTags(Und) && strings.HasPrefix(, "x-") {
.str =
.pVariant = 0
.pExt = 0
return
}
var [max99thPercentileSize]byte // avoid extra memory allocation in most cases.
:= [:.genCoreBytes([:])]
if != "" {
:= len() - int(.pVariant)
= append(, '-')
= append(, ...)
.pVariant = uint8(int(.pVariant) + )
.pExt = uint16(int(.pExt) + )
} else {
.pVariant = uint8(len())
.pExt = uint16(len())
}
.str = string()
}
, , := .Raw()
= Tag{LangID: , ScriptID: , RegionID: }
if .RegionID == 0 && .ScriptID != 0 && .LangID != 0 {
, := addTags(Tag{LangID: .LangID})
if .ScriptID == .ScriptID {
return Tag{LangID: .LangID}
}
}
return
}
if .LangID != 0 {
if .RegionID != 0 {
:= .ScriptID
if == 0 {
, := addTags()
= .ScriptID
}
for := range parents {
if Language(parents[].lang) == .LangID && Script(parents[].maxScript) == {
for , := range parents[].fromRegion {
if Region() == .RegionID {
return Tag{
LangID: .LangID,
ScriptID: Script(parents[].script),
RegionID: Region(parents[].toRegion),
}
}
}
}
}
func ( Tag) ( string) string {
if , , := .findTypeForKey(); != {
return .str[:]
}
return ""
}
var (
errPrivateUse = errors.New("cannot set a key on a private use tag")
errInvalidArguments = errors.New("invalid key or type")
)
func ( Tag) (, string) (Tag, error) {
if .IsPrivateUse() {
return , errPrivateUse
}
if len() != 2 {
return , errInvalidArguments
}
if == "" {
, , := .findTypeForKey()
-= 4
if ( == len(.str) || .str[+2] == '-') && .str[-2] == '-' {
-= 2
}
if == int(.pVariant) && == len(.str) {
.str = ""
.pVariant, .pExt = 0, 0
} else {
.str = fmt.Sprintf("%s%s", .str[:], .str[:])
}
}
return , nil
}
if len() < 3 || len() > 8 {
return , errInvalidArguments
}
var (
[maxCoreSize + maxSimpleUExtensionSize]byte
int // start of the -u extension.
)
if .str == "" {
= .genCoreBytes([:])
[] = '-'
++
}
:= [:]
copy(, "u-")
copy([2:], )
[4] = '-'
= [:5+copy([5:], )]
:= makeScanner()
if parseExtensions(&); .err != nil {
return , .err
}
++
:= ""
if == {
return , , true
= [+1 : ]
if > {
return , , true
+= 7 // 4 + 3
+= 4
func ( int) (Region, error) {
return getRegionM49()
}
func ( Region) () bool {
if == 0 {
return false
}
return int(regionInclusion[]) < len(regionContainment)
}
func ( Region) ( Region) bool {
if == {
return true
}
:= regionInclusion[]
if >= nRegionGroups {
return false
}
:= regionContainment[]
:= regionInclusion[]
:= regionInclusionBits[]
if >= nRegionGroups {
return & != 0
}
return &^ == 0
}
var errNoTLD = errors.New("language: region is not a valid ccTLD")
func ( Region) () Region {
if := normRegion(); != 0 {
return
}
return
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |