mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-08-07 19:50:39 +00:00
Bump go-openapi dependencies to latest versions: - github.com/go-openapi/jsonpointer v0.21.0 → v0.22.4 - github.com/go-openapi/jsonreference v0.20.2 → v0.21.4 - github.com/go-openapi/swag v0.23.0 → v0.25.4 The new swag version has been restructured into a multi-module monorepo with submodules (cmdutils, conv, fileutils, jsonname, jsonutils, loading, mangling, netutils, stringutils, typeutils, yamlutils). As a result: - mailru/easyjson and josharian/intern are no longer transitive deps and have been removed from vendor - go-openapi/jsonpointer and go-openapi/swag no longer reference unwanted deps davecgh/go-spew, mailru/easyjson, or gopkg.in/yaml.v3 - Updated hack/unwanted-dependencies.json accordingly Signed-off-by: Davanum Srinivas <davanum@gmail.com>
119 lines
2.1 KiB
Go
119 lines
2.1 KiB
Go
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package mangling
|
|
|
|
import (
|
|
"strings"
|
|
"unicode"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
// Removes leading whitespaces
|
|
func trim(str string) string { return strings.TrimSpace(str) }
|
|
|
|
// upper is strings.ToUpper() combined with trim
|
|
func upper(str string) string {
|
|
return strings.ToUpper(trim(str))
|
|
}
|
|
|
|
// lower is strings.ToLower() combined with trim
|
|
func lower(str string) string {
|
|
return strings.ToLower(trim(str))
|
|
}
|
|
|
|
// isEqualFoldIgnoreSpace is the same as strings.EqualFold, but
|
|
// it ignores leading and trailing blank spaces in the compared
|
|
// string.
|
|
//
|
|
// base is assumed to be composed of upper-cased runes, and be already
|
|
// trimmed.
|
|
//
|
|
// This code is heavily inspired from strings.EqualFold.
|
|
func isEqualFoldIgnoreSpace(base []rune, str string) bool {
|
|
var i, baseIndex int
|
|
// equivalent to b := []byte(str), but without data copy
|
|
b := hackStringBytes(str)
|
|
|
|
for i < len(b) {
|
|
if c := b[i]; c < utf8.RuneSelf {
|
|
// fast path for ASCII
|
|
if c != ' ' && c != '\t' {
|
|
break
|
|
}
|
|
i++
|
|
|
|
continue
|
|
}
|
|
|
|
// unicode case
|
|
r, size := utf8.DecodeRune(b[i:])
|
|
if !unicode.IsSpace(r) {
|
|
break
|
|
}
|
|
i += size
|
|
}
|
|
|
|
if i >= len(b) {
|
|
return len(base) == 0
|
|
}
|
|
|
|
for _, baseRune := range base {
|
|
if i >= len(b) {
|
|
break
|
|
}
|
|
|
|
if c := b[i]; c < utf8.RuneSelf {
|
|
// single byte rune case (ASCII)
|
|
if baseRune >= utf8.RuneSelf {
|
|
return false
|
|
}
|
|
|
|
baseChar := byte(baseRune)
|
|
if c != baseChar && ((c < 'a') || (c > 'z') || (c-'a'+'A' != baseChar)) {
|
|
return false
|
|
}
|
|
|
|
baseIndex++
|
|
i++
|
|
|
|
continue
|
|
}
|
|
|
|
// unicode case
|
|
r, size := utf8.DecodeRune(b[i:])
|
|
if unicode.ToUpper(r) != baseRune {
|
|
return false
|
|
}
|
|
baseIndex++
|
|
i += size
|
|
}
|
|
|
|
if baseIndex != len(base) {
|
|
return false
|
|
}
|
|
|
|
// all passed: now we should only have blanks
|
|
for i < len(b) {
|
|
if c := b[i]; c < utf8.RuneSelf {
|
|
// fast path for ASCII
|
|
if c != ' ' && c != '\t' {
|
|
return false
|
|
}
|
|
i++
|
|
|
|
continue
|
|
}
|
|
|
|
// unicode case
|
|
r, size := utf8.DecodeRune(b[i:])
|
|
if !unicode.IsSpace(r) {
|
|
return false
|
|
}
|
|
|
|
i += size
|
|
}
|
|
|
|
return true
|
|
}
|