diff --git a/vendor.mod b/vendor.mod index 8b1affe793..46be786ffc 100644 --- a/vendor.mod +++ b/vendor.mod @@ -23,7 +23,7 @@ require ( github.com/docker/docker-credential-helpers v0.9.9 github.com/docker/go-connections v0.8.1 github.com/docker/go-units v0.5.0 - github.com/fvbommel/sortorder v1.1.0 + github.com/fvbommel/sortorder v1.2.0 github.com/go-jose/go-jose/v4 v4.1.4 github.com/go-viper/mapstructure/v2 v2.5.0 github.com/gogo/protobuf v1.3.2 diff --git a/vendor.sum b/vendor.sum index c1e8e5b293..cab284654f 100644 --- a/vendor.sum +++ b/vendor.sum @@ -49,8 +49,8 @@ github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE= github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeORc= github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE= -github.com/fvbommel/sortorder v1.1.0 h1:fUmoe+HLsBTctBDoaBwpQo5N+nrCp8g/BjKb/6ZQmYw= -github.com/fvbommel/sortorder v1.1.0/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0= +github.com/fvbommel/sortorder v1.2.0 h1:TRIiRiGX+djh3Yf4FVxmWmAcYfIr5dH0NbzJWOSAWZk= +github.com/fvbommel/sortorder v1.2.0/go.mod h1:LbhO04ijZIeUuvz9B9BkI/qYrpZZEn1gWhxv4QjUKVs= github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA= github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= diff --git a/vendor/github.com/fvbommel/sortorder/natsort.go b/vendor/github.com/fvbommel/sortorder/natsort.go index e4f15110b8..5eba2bc6f5 100644 --- a/vendor/github.com/fvbommel/sortorder/natsort.go +++ b/vendor/github.com/fvbommel/sortorder/natsort.go @@ -1,5 +1,7 @@ package sortorder +import "cmp" + // Natural implements sort.Interface to sort strings in natural order. This // means that e.g. "abc2" < "abc12". // @@ -25,18 +27,36 @@ func isDigit(b byte) bool { return '0' <= b && b <= '9' } // // Limitation: only ASCII digits (0-9) are considered. func NaturalLess(str1, str2 string) bool { + return NaturalCompare(str1, str2) < 0 +} + +// NaturalCompare compares str1 and str2 using the same natural ordering as +// [NaturalLess]. It returns a negative value if str1 sorts before str2, a +// positive value if str1 sorts after str2, and zero if str1 and str2 are equal. +// +// NaturalCompare is suitable for APIs that accept a three-way comparison +// function, such as [slices.SortFunc] and [slices.SortStableFunc]. +func NaturalCompare(str1, str2 string) int { idx1, idx2 := 0, 0 for idx1 < len(str1) && idx2 < len(str2) { c1, c2 := str1[idx1], str2[idx2] dig1, dig2 := isDigit(c1), isDigit(c2) switch { - case dig1 != dig2: // Digits before other characters. - return dig1 // True if LHS is a digit, false if the RHS is one. + case dig1 != dig2: + // The first difference is that one is a digit and the other is not. + // That means that one (possibly empty) non-digit string has ended, and the other has not. + // The one that has ended is ordered before the one that continues, + // for example: "ab1" < "abc1" after skipping the matching "ab" prefix. + // This means the side with the digit is ordered before the other one. + if dig1 { + return -1 + } + return 1 case !dig1: // && !dig2, because dig1 == dig2 // UTF-8 compares bytewise-lexicographically, no need to decode // codepoints. if c1 != c2 { - return c1 < c2 + return cmp.Compare(c1, c2) } idx1++ idx2++ @@ -55,22 +75,22 @@ func NaturalLess(str1, str2 string) bool { // If lengths of numbers with non-zero prefix differ, the shorter // one is less. if len1, len2 := idx1-nonZero1, idx2-nonZero2; len1 != len2 { - return len1 < len2 + return cmp.Compare(len1, len2) } // If they're equally long, string comparison is correct. if nr1, nr2 := str1[nonZero1:idx1], str2[nonZero2:idx2]; nr1 != nr2 { - return nr1 < nr2 + return cmp.Compare(nr1, nr2) } // Otherwise, the one with less zeros is less. // Because everything up to the number is equal, comparing the index // after the zeros is sufficient. if nonZero1 != nonZero2 { - return nonZero1 < nonZero2 + return cmp.Compare(nonZero1, nonZero2) } } // They're identical so far, so continue comparing. } // So far they are identical. At least one is ended. If the other continues, // it sorts last. - return len(str1) < len(str2) + return cmp.Compare(len(str1), len(str2)) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 1a2ff3894f..39b5a29ce6 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -91,8 +91,8 @@ github.com/docker/go-units # github.com/felixge/httpsnoop v1.1.0 ## explicit; go 1.25 github.com/felixge/httpsnoop -# github.com/fvbommel/sortorder v1.1.0 -## explicit; go 1.13 +# github.com/fvbommel/sortorder v1.2.0 +## explicit; go 1.21 github.com/fvbommel/sortorder # github.com/go-jose/go-jose/v4 v4.1.4 ## explicit; go 1.24.0