go.text/language: make Region.ISO3 return "ZZZ" in case of non-exising ISO3

code.
The occurence of a non-existing ISO3 code is rather rare to the point it
seems better to just return something.

R=r
CC=golang-codereviews
https://golang.org/cl/55230043
This commit is contained in:
Marcel van Lohuizen 2014-02-04 14:03:48 +01:00
Родитель 66b4d1c3e7
Коммит 73f318262f
2 изменённых файлов: 7 добавлений и 7 удалений

Просмотреть файл

@ -334,10 +334,10 @@ func (r regionID) String() string {
// ISO3 returns the 3-letter ISO code of r.
// Note that not all regions have a 3-letter ISO code.
// In such cases this method returns the empty string.
// In such cases this method returns "ZZZ".
func (r regionID) ISO3() string {
if r < isoRegionOffset {
return ""
return "ZZZ"
}
r -= isoRegionOffset
reg := regionISO[r<<2:]
@ -345,7 +345,7 @@ func (r regionID) ISO3() string {
case 0:
return altRegionISO3[reg[3]:][:3]
case ' ':
return ""
return "ZZZ"
}
return reg[0:1] + reg[2:4]
}

Просмотреть файл

@ -196,14 +196,14 @@ func TestRegionISO3(t *testing.T) {
tests := []struct {
from, iso3, to string
}{
{" ", "", ""},
{"000", "", ""},
{" ", "ZZZ", "ZZ"},
{"000", "ZZZ", "ZZ"},
{"AA", "AAA", ""},
{"CT", "CTE", ""},
{"DY", "DHY", ""},
{"EU", "QUU", ""},
{"HV", "HVO", ""},
{"IC", "", ""},
{"IC", "ZZZ", "ZZ"},
{"JT", "JTN", ""},
{"PZ", "PCZ", ""},
{"QU", "QUU", "EU"},
@ -213,7 +213,7 @@ func TestRegionISO3(t *testing.T) {
{"TF", "ATF", ""},
{"FX", "FXX", ""},
{"ZZ", "ZZZ", ""},
{"419", "", ""},
{"419", "ZZZ", "ZZ"},
}
for _, tt := range tests {
r, _ := getRegionID(b(tt.from))