frostfs-locode-db/pkg/locode/column/country.go
George Bartolomey 840b20538b
[#7] Add local tool for building database file
Added frostfs-locode-db CLI utility that can generate and view UN/LOCODE
database files. Go package
git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/locode copied to
this repository to eliminate interdependency between frostfs-node and
frostfs-locode-db projects. The process of building database files
reduced to starting make command.

Signed-off-by: George Bartolomey <george@bh4.ru>
2024-07-09 18:54:05 +03:00

38 lines
780 B
Go

package locodecolumn
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode"
)
const countryCodeLen = 2
// CountryCode represents ISO 3166 alpha-2 Country Code.
type CountryCode [countryCodeLen]uint8
// Symbols returns digits of the country code.
func (cc *CountryCode) Symbols() [countryCodeLen]uint8 {
return *cc
}
// CountryCodeFromString parses a string and returns the country code.
func CountryCodeFromString(s string) (*CountryCode, error) {
if l := len(s); l != countryCodeLen {
return nil, fmt.Errorf("incorrect country code length: expect: %d, got: %d",
countryCodeLen,
l,
)
}
for i := range s {
if !isUpperAlpha(s[i]) {
return nil, locode.ErrInvalidString
}
}
cc := CountryCode{}
copy(cc[:], s)
return &cc, nil
}