diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index d307ff55..53259895 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -19,8 +19,6 @@ package parser import ( "fmt" "strings" - - specs "tags.cncf.io/container-device-interface/specs-go" ) // QualifiedName returns the qualified name for a device. @@ -107,7 +105,11 @@ func ParseDevice(device string) (string, string, string) { // If parsing fails, an empty vendor and the class set to the // verbatim input is returned. func ParseQualifier(kind string) (string, string) { - return specs.ParseQualifier(kind) + parts := strings.SplitN(kind, "/", 2) + if len(parts) != 2 || parts[0] == "" || parts[1] == "" { + return "", kind + } + return parts[0], parts[1] } // ValidateVendorName checks the validity of a vendor name. @@ -196,7 +198,7 @@ func ValidateDeviceName(name string) error { // IsLetter reports whether the rune is a letter. func IsLetter(c rune) bool { - return specs.IsLetter(c) + return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') } // IsDigit reports whether the rune is a digit. diff --git a/specs-go/parser.go b/specs-go/parser.go index 7bdf0ea4..f6c07da4 100644 --- a/specs-go/parser.go +++ b/specs-go/parser.go @@ -18,14 +18,14 @@ package specs import "strings" -// ParseQualifier splits a device qualifier into vendor and class. +// parseQualifier splits a device qualifier into vendor and class. // The syntax for a device qualifier is // // "/" // // If parsing fails, an empty vendor and the class set to the // verbatim input is returned. -func ParseQualifier(kind string) (string, string) { +func parseQualifier(kind string) (string, string) { parts := strings.SplitN(kind, "/", 2) if len(parts) != 2 || parts[0] == "" || parts[1] == "" { return "", kind @@ -33,7 +33,7 @@ func ParseQualifier(kind string) (string, string) { return parts[0], parts[1] } -// IsLetter reports whether the rune is a letter. -func IsLetter(c rune) bool { +// isLetter reports whether the rune is an ASCII letter. +func isLetter(c rune) bool { return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') } diff --git a/specs-go/version.go b/specs-go/version.go index 9feebca7..cd5dcaaa 100644 --- a/specs-go/version.go +++ b/specs-go/version.go @@ -70,7 +70,7 @@ func ValidateVersion(spec *Spec) error { if err != nil { return fmt.Errorf("could not determine minimum required version: %w", err) } - if newVersion(minVersion).IsGreaterThan(newVersion(spec.Version)) { + if newVersion(minVersion).isGreaterThan(newVersion(spec.Version)) { return fmt.Errorf("the spec version must be at least v%v", minVersion) } return nil @@ -97,12 +97,12 @@ func (v version) String() string { } // IsGreaterThan checks with a version is greater than the specified version. -func (v version) IsGreaterThan(o version) bool { +func (v version) isGreaterThan(o version) bool { return semver.Compare(string(v), string(o)) > 0 } // IsLatest checks whether the version is the latest supported version -func (v version) IsLatest() bool { +func (v version) isLatest() bool { return v == vCurrent } @@ -126,11 +126,11 @@ func (r requiredVersionMap) requiredVersion(spec *Spec) version { if isRequired == nil { continue } - if isRequired(spec) && v.IsGreaterThan(minVersion) { + if isRequired(spec) && v.isGreaterThan(minVersion) { minVersion = v } // If we have already detected the latest version then no later version could be detected - if minVersion.IsLatest() { + if minVersion.isLatest() { break } } @@ -183,7 +183,7 @@ func requiresV060(spec *Spec) bool { } // The v0.6.0 spec allows dots "." in Kind name label (class) - vendor, class := ParseQualifier(spec.Kind) + vendor, class := parseQualifier(spec.Kind) if vendor != "" { if strings.ContainsRune(class, '.') { return true @@ -199,7 +199,7 @@ func requiresV050(spec *Spec) bool { for _, d := range spec.Devices { // The v0.5.0 spec allowed device names to start with a digit instead of requiring a letter - if len(d.Name) > 0 && !IsLetter(rune(d.Name[0])) { + if len(d.Name) > 0 && !isLetter(rune(d.Name[0])) { return true } edits = append(edits, &d.ContainerEdits)