diff --git a/go.mod b/go.mod index 32363b994..72f920e39 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/lib/pq v1.10.9 github.com/lomik/og-rek v0.0.0-20170411191824-628eefeb8d80 github.com/lomik/zapwriter v0.0.0-20210624082824-c1161d1eb463 - github.com/maruel/natural v1.1.1 + github.com/maruel/natural v1.2.1 github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12 github.com/msaf1980/go-metrics v0.0.14 github.com/msaf1980/go-stringutils v0.1.6 diff --git a/go.sum b/go.sum index d0445f0fa..fb196626d 100644 --- a/go.sum +++ b/go.sum @@ -123,8 +123,8 @@ github.com/lomik/og-rek v0.0.0-20170411191824-628eefeb8d80 h1:KVyDGUXjVOdHQt24wI github.com/lomik/og-rek v0.0.0-20170411191824-628eefeb8d80/go.mod h1:T7SQVaLtK7mcQIEVzveZVJzsDQpAtzTs2YoezrIBdvI= github.com/lomik/zapwriter v0.0.0-20210624082824-c1161d1eb463 h1:SN/0TEkyYpp8tit79JPUnecebCGZsXiYYPxN8i3I6Rk= github.com/lomik/zapwriter v0.0.0-20210624082824-c1161d1eb463/go.mod h1:rWIJAUD2hPOAyOzc3jBShAhN4CAZeLAyzUA/n8tE8ak= -github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo= -github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg= +github.com/maruel/natural v1.2.1 h1:G/y4pwtTA07lbQsMefvsmEO0VN0NfqpxprxXDM4R/4o= +github.com/maruel/natural v1.2.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg= github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12 h1:dd7vnTDfjtwCETZDrRe+GPYNLA1jBtbZeyfyE8eZCyk= github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12/go.mod h1:i/KKcxEWEO8Yyl11DYafRPKOPVYTrhxiTRigjtEEXZU= github.com/msaf1980/go-metrics v0.0.14 h1:gD0kCG5MDbon33Nkz49yW6kz3yu0DHzDN0SxjGTWlTA= diff --git a/vendor/github.com/maruel/natural/natsort.go b/vendor/github.com/maruel/natural/natural.go similarity index 83% rename from vendor/github.com/maruel/natural/natsort.go rename to vendor/github.com/maruel/natural/natural.go index df3ee0cba..e568095ec 100644 --- a/vendor/github.com/maruel/natural/natsort.go +++ b/vendor/github.com/maruel/natural/natural.go @@ -12,6 +12,7 @@ package natural import ( "strconv" + "strings" ) // Less does a 'natural' comparison on the two strings. @@ -20,13 +21,22 @@ import ( // // This function does no memory allocation. func Less(a, b string) bool { + return Compare(a, b) < 0 +} + +// Compare does a 'natural' comparison on the two strings. +// +// It treats digits as decimal numbers, so that Compare("10", "2") return >0. +// +// This function does no memory allocation. +func Compare(a, b string) int { for { if p := commonPrefix(a, b); p != 0 { a = a[p:] b = b[p:] } if len(a) == 0 { - return len(b) != 0 + return -len(b) } if ia := digits(a); ia > 0 { if ib := digits(b); ib > 0 { @@ -35,7 +45,8 @@ func Less(a, b string) bool { bn, berr := strconv.ParseUint(b[:ib], 10, 64) if aerr == nil && berr == nil { if an != bn { - return an < bn + // #nosec G40 + return int(an - bn) } // Semantically the same digits, e.g. "00" == "0", "01" == "1". In // this case, only continue processing if there's trailing data on @@ -48,12 +59,14 @@ func Less(a, b string) bool { } } } - return a < b + return strings.Compare(a, b) } } // StringSlice attaches the methods of Interface to []string, sorting in // increasing order using natural order. +// +// It is now obsolete, use slices.Sort() along with natural.Compare instead. type StringSlice []string func (p StringSlice) Len() int { return len(p) } diff --git a/vendor/modules.txt b/vendor/modules.txt index aa6f0ffa0..f627a08de 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -101,7 +101,7 @@ github.com/lomik/og-rek # github.com/lomik/zapwriter v0.0.0-20210624082824-c1161d1eb463 ## explicit; go 1.16 github.com/lomik/zapwriter -# github.com/maruel/natural v1.1.1 +# github.com/maruel/natural v1.2.1 ## explicit; go 1.21 github.com/maruel/natural # github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12