x/model: NamePartKind -> NamePart

This commit is contained in:
Blake Mizerany 2024-04-05 23:13:22 -07:00
parent 0bee38f6b5
commit fb0782b7a9
2 changed files with 10 additions and 10 deletions

View File

@ -22,9 +22,9 @@ var (
const MaxNamePartLen = 128 const MaxNamePartLen = 128
type NamePartKind int type NamePart int
var kindNames = map[NamePartKind]string{ var kindNames = map[NamePart]string{
Invalid: "Invalid", Invalid: "Invalid",
Host: "Host", Host: "Host",
Namespace: "Namespace", Namespace: "Namespace",
@ -33,13 +33,13 @@ var kindNames = map[NamePartKind]string{
Build: "Build", Build: "Build",
} }
func (k NamePartKind) String() string { func (k NamePart) String() string {
return cmp.Or(kindNames[k], "Unknown") return cmp.Or(kindNames[k], "Unknown")
} }
// Levels of concreteness // Levels of concreteness
const ( const (
Invalid NamePartKind = iota Invalid NamePart = iota
Host Host
Namespace Namespace
Model Model
@ -346,8 +346,8 @@ func (r Name) Parts() []string {
// //
// As a special case, question marks are ignored so they may be used as // As a special case, question marks are ignored so they may be used as
// placeholders for missing parts in string literals. // placeholders for missing parts in string literals.
func NameParts(s string) iter.Seq2[NamePartKind, string] { func NameParts(s string) iter.Seq2[NamePart, string] {
return func(yield func(NamePartKind, string) bool) { return func(yield func(NamePart, string) bool) {
if strings.HasPrefix(s, "http://") { if strings.HasPrefix(s, "http://") {
s = s[len("http://"):] s = s[len("http://"):]
} }
@ -359,7 +359,7 @@ func NameParts(s string) iter.Seq2[NamePartKind, string] {
return return
} }
yieldValid := func(kind NamePartKind, part string) bool { yieldValid := func(kind NamePart, part string) bool {
if !isValidPart(kind, part) { if !isValidPart(kind, part) {
yield(Invalid, "") yield(Invalid, "")
return false return false
@ -438,7 +438,7 @@ func (r Name) Valid() bool {
} }
// isValidPart returns true if given part is valid ascii [a-zA-Z0-9_\.-] // isValidPart returns true if given part is valid ascii [a-zA-Z0-9_\.-]
func isValidPart(kind NamePartKind, s string) bool { func isValidPart(kind NamePart, s string) bool {
if s == "" { if s == "" {
return false return false
} }
@ -450,7 +450,7 @@ func isValidPart(kind NamePartKind, s string) bool {
return true return true
} }
func isValidByte(kind NamePartKind, c byte) bool { func isValidByte(kind NamePart, c byte) bool {
if kind == Namespace && c == '.' { if kind == Namespace && c == '.' {
return false return false
} }

View File

@ -72,7 +72,7 @@ func TestNameParts(t *testing.T) {
} }
func TestNamePartString(t *testing.T) { func TestNamePartString(t *testing.T) {
if g := NamePartKind(-1).String(); g != "Unknown" { if g := NamePart(-1).String(); g != "Unknown" {
t.Errorf("Unknown part = %q; want %q", g, "Unknown") t.Errorf("Unknown part = %q; want %q", g, "Unknown")
} }
for kind, name := range kindNames { for kind, name := range kindNames {