github.com/elopio/cli@v6.21.2-0.20160902224010-ea909d1fdb2f+incompatible/utils/sortutils/alphabetic.go (about) 1 package sortutils 2 3 import "unicode" 4 5 type Alphabetic []string 6 7 func (s Alphabetic) Len() int { return len(s) } 8 func (s Alphabetic) Swap(i, j int) { s[i], s[j] = s[j], s[i] } 9 10 func (s Alphabetic) Less(i, j int) bool { 11 return SortAlphabetic(s[i], s[j]) 12 } 13 14 func SortAlphabetic(a string, b string) bool { 15 iRunes := []rune(a) 16 jRunes := []rune(b) 17 18 max := len(iRunes) 19 if max > len(jRunes) { 20 max = len(jRunes) 21 } 22 23 for idx := 0; idx < max; idx++ { 24 ir := iRunes[idx] 25 jr := jRunes[idx] 26 27 lir := unicode.ToLower(ir) 28 ljr := unicode.ToLower(jr) 29 30 if lir != ljr { 31 return lir < ljr 32 } 33 34 // the lowercase runes are the same, so compare the original 35 if ir != jr { 36 return ir < jr 37 } 38 } 39 40 return false 41 }