From 8de8603e48f161faeea7264e04ed97f2f7b93262 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Fri, 9 Aug 2024 14:07:22 +0300 Subject: [PATCH] Remove specs-go/parsing APIs Signed-off-by: Ed Bartosh --- specs-go/parser.go | 39 --------------------------------------- specs-go/version.go | 15 ++++++--------- 2 files changed, 6 insertions(+), 48 deletions(-) delete mode 100644 specs-go/parser.go diff --git a/specs-go/parser.go b/specs-go/parser.go deleted file mode 100644 index f6c07da4..00000000 --- a/specs-go/parser.go +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright © The CDI Authors - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package specs - -import "strings" - -// 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) { - parts := strings.SplitN(kind, "/", 2) - if len(parts) != 2 || parts[0] == "" || parts[1] == "" { - return "", kind - } - return parts[0], parts[1] -} - -// 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 3c1f2919..7f0bbdd8 100644 --- a/specs-go/version.go +++ b/specs-go/version.go @@ -183,14 +183,11 @@ func requiresV060(spec *Spec) bool { } // The v0.6.0 spec allows dots "." in Kind name label (class) - vendor, class := parseQualifier(spec.Kind) - if vendor != "" { - if strings.ContainsRune(class, '.') { - return true - } + if !strings.Contains(spec.Kind, "/") { + return false } - - return false + class := strings.SplitN(spec.Kind, "/", 2)[1] + return strings.Contains(class, ".") } // requiresV050 returns true if the spec uses v0.5.0 features @@ -198,8 +195,8 @@ func requiresV050(spec *Spec) bool { var edits []*ContainerEdits 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])) { + // The v0.5.0 spec allowed device name to start with a digit + if len(d.Name) > 0 && '0' <= d.Name[0] && d.Name[0] <= '9' { return true } edits = append(edits, &d.ContainerEdits)