frostfs-node/pkg/util/locode/column/location.go
Elizaveta Chichindaeva cc7a723d77 [#1320] English Check
Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
2022-05-11 10:40:02 +03:00

33 lines
722 B
Go

package locodecolumn
import (
"github.com/nspcc-dev/neofs-node/pkg/util/locode"
)
const locationCodeLen = 3
// LocationCode represents 3-character code for the location.
type LocationCode [locationCodeLen]uint8
// Symbols returns characters of the location code.
func (lc *LocationCode) Symbols() [locationCodeLen]uint8 {
return *lc
}
// LocationCodeFromString parses a string and returns the location code.
func LocationCodeFromString(s string) (*LocationCode, error) {
if len(s) != locationCodeLen {
return nil, locode.ErrInvalidString
}
for i := range s {
if !isUpperAlpha(s[i]) && !isDigit(s[i]) {
return nil, locode.ErrInvalidString
}
}
lc := LocationCode{}
copy(lc[:], s)
return &lc, nil
}