1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-05 01:34:25 +00:00
gitea/modules/base/natural_sort.go
wxiaoguang ebff37ae09
Improve natural sort (#29611)
Hugely simplify the code, and add more tests (only new approach could
pass)
2024-03-05 15:13:35 +00:00

16 lines
396 B
Go

// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package base
import (
"golang.org/x/text/collate"
"golang.org/x/text/language"
)
// NaturalSortLess compares two strings so that they could be sorted in natural order
func NaturalSortLess(s1, s2 string) bool {
c := collate.New(language.English, collate.Numeric)
return c.CompareString(s1, s2) < 0
}