internal/language: export the root language tag
Change-Id: I61eef748368d6d30cd9e937d78ed903206c59803
Reviewed-on: https://go-review.googlesource.com/98436
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ross Light <light@google.com>
diff --git a/internal/language/language.go b/internal/language/language.go
index 7875a7c..aa5f5f4 100644
--- a/internal/language/language.go
+++ b/internal/language/language.go
@@ -31,7 +31,7 @@
// Tag represents a BCP 47 language tag. It is used to specify an instance of a
// specific language or locale. All language tag values are guaranteed to be
-// well-formed.
+// well-formed. The zero value of Tag is Und.
type Tag struct {
// TODO: the following fields have the form TagTypeID. This name is chosen
// to allow refactoring the public package without conflicting with its
@@ -80,7 +80,7 @@
if int(t.pVariant) < len(t.str) {
return false
}
- return t.equalTags(und)
+ return t.equalTags(Und)
}
// IsPrivateUse reports whether the Tag consists solely of an IsPrivateUse use
@@ -100,7 +100,7 @@
if t.pVariant > 0 {
extra = extra[1:]
}
- if t.equalTags(und) && strings.HasPrefix(extra, "x-") {
+ if t.equalTags(Und) && strings.HasPrefix(extra, "x-") {
t.str = extra
t.pVariant = 0
t.pExt = 0
@@ -241,12 +241,12 @@
// "und" instead of the base language.
base, _ := addTags(Tag{LangID: t.LangID})
if base.ScriptID != t.ScriptID {
- return und
+ return Und
}
return Tag{LangID: t.LangID}
}
}
- return und
+ return Und
}
// ParseExtension parses s as an extension and returns it on success.
diff --git a/internal/language/match.go b/internal/language/match.go
index bcefcd9..75a2dbc 100644
--- a/internal/language/match.go
+++ b/internal/language/match.go
@@ -205,7 +205,7 @@
// minimizeTags mimics the behavior of the ICU 51 C implementation.
func minimizeTags(t Tag) (Tag, error) {
- if t.equalTags(und) {
+ if t.equalTags(Und) {
return t, nil
}
max, err := addTags(t)
diff --git a/internal/language/parse.go b/internal/language/parse.go
index eca4663..3c48288 100644
--- a/internal/language/parse.go
+++ b/internal/language/parse.go
@@ -229,7 +229,7 @@
func Parse(s string) (t Tag, err error) {
// TODO: consider supporting old-style locale key-value pairs.
if s == "" {
- return und, ErrSyntax
+ return Und, ErrSyntax
}
if len(s) <= maxAltTaglen {
b := [maxAltTaglen]byte{}
@@ -251,7 +251,7 @@
}
func parse(scan *scanner, s string) (t Tag, err error) {
- t = und
+ t = Und
var end int
if n := len(scan.token); n <= 1 {
scan.toLower(0, len(scan.b))
@@ -260,7 +260,7 @@
}
end = parseExtensions(scan)
} else if n >= 4 {
- return und, ErrSyntax
+ return Und, ErrSyntax
} else { // the usual case
t, end = parseTag(scan)
if n := len(scan.token); n == 1 {
diff --git a/internal/language/tags.go b/internal/language/tags.go
index 5d47329..e7afd31 100644
--- a/internal/language/tags.go
+++ b/internal/language/tags.go
@@ -4,8 +4,6 @@
package language
-// TODO: Various sets of commonly use tags and regions.
-
// MustParse is like Parse, but panics if the given BCP 47 tag cannot be parsed.
// It simplifies safe initialization of Tag values.
func MustParse(s string) Tag {
@@ -46,4 +44,5 @@
return r
}
-var und = Tag{}
+// Und is the root language.
+var Und Tag