runes.go 571 B

123456789101112131415161718192021222324252627282930
  1. package types
  2. import "unicode"
  3. // LessRunes compares two rune values, and returns true if the first argument is lexicographicaly smaller.
  4. func LessRunes(iRunes, jRunes []rune) bool {
  5. max := len(iRunes)
  6. if max > len(jRunes) {
  7. max = len(jRunes)
  8. }
  9. for idx := 0; idx < max; idx++ {
  10. ir := iRunes[idx]
  11. jr := jRunes[idx]
  12. lir := unicode.ToLower(ir)
  13. ljr := unicode.ToLower(jr)
  14. if lir != ljr {
  15. return lir < ljr
  16. }
  17. // the lowercase runes are the same, so compare the original
  18. if ir != jr {
  19. return ir < jr
  20. }
  21. }
  22. return len(iRunes) < len(jRunes)
  23. }