forked from TrueCloudLab/frostfs-node
[#316] locode: Define UN/LOCODE table data types
Define the data types needed to work with LOCODE's in NeoFS (country code, location code, coordinates). Implement string parsers for new types. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
137ef25d3e
commit
0be35859ed
4 changed files with 268 additions and 0 deletions
33
pkg/util/locode/column/location.go
Normal file
33
pkg/util/locode/column/location.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
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 string and returns 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue