mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-31 22:41:53 +02:00
Merge pull request #6149 from bep/sort-caseinsensitive
Implement lexicographically string sorting
This commit is contained in:
committed by
GitHub
parent
a4f96a9d8c
commit
53077b0da5
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
var comp = compare.New()
|
||||
var sortComp = compare.New(true)
|
||||
|
||||
// Sort returns a sorted sequence.
|
||||
func (ns *Namespace) Sort(seq interface{}, args ...interface{}) (interface{}, error) {
|
||||
@@ -133,15 +133,15 @@ func (p pairList) Less(i, j int) bool {
|
||||
if iv.IsValid() {
|
||||
if jv.IsValid() {
|
||||
// can only call Interface() on valid reflect Values
|
||||
return comp.Lt(iv.Interface(), jv.Interface())
|
||||
return sortComp.Lt(iv.Interface(), jv.Interface())
|
||||
}
|
||||
// if j is invalid, test i against i's zero value
|
||||
return comp.Lt(iv.Interface(), reflect.Zero(iv.Type()))
|
||||
return sortComp.Lt(iv.Interface(), reflect.Zero(iv.Type()))
|
||||
}
|
||||
|
||||
if jv.IsValid() {
|
||||
// if i is invalid, test j against j's zero value
|
||||
return comp.Lt(reflect.Zero(jv.Type()), jv.Interface())
|
||||
return sortComp.Lt(reflect.Zero(jv.Type()), jv.Interface())
|
||||
}
|
||||
|
||||
return false
|
||||
|
Reference in New Issue
Block a user