mirror of
https://github.com/tmedwards/tweego.git
synced 2025-07-04 21:50:33 -04:00
Initial Bitbucket→GitHub migration commit, based on release v2.0.0.
This commit is contained in:
commit
57e1aa52ff
36 changed files with 5026 additions and 0 deletions
48
sort.go
Normal file
48
sort.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
Copyright © 2014–2019 Thomas Michael Edwards. All rights reserved.
|
||||
Use of this source code is governed by a Simplified BSD License which
|
||||
can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
)
|
||||
|
||||
type StringsInsensitively []string
|
||||
|
||||
func (p StringsInsensitively) Len() int {
|
||||
return len(p)
|
||||
}
|
||||
|
||||
func (p StringsInsensitively) Swap(i, j int) {
|
||||
p[i], p[j] = p[j], p[i]
|
||||
}
|
||||
|
||||
func (p StringsInsensitively) Less(i, j int) bool {
|
||||
iRunes := []rune(p[i])
|
||||
jRunes := []rune(p[j])
|
||||
|
||||
uBound := len(iRunes)
|
||||
if uBound > len(jRunes) {
|
||||
uBound = len(jRunes)
|
||||
}
|
||||
|
||||
for pos := 0; pos < uBound; pos++ {
|
||||
iR := iRunes[pos]
|
||||
jR := jRunes[pos]
|
||||
|
||||
iRLo := unicode.ToLower(iR)
|
||||
jRLo := unicode.ToLower(jR)
|
||||
|
||||
if iRLo != jRLo {
|
||||
return iRLo < jRLo
|
||||
}
|
||||
if iR != jR {
|
||||
return iR < jR
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue