text.go 860 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package text
  2. import (
  3. "strings"
  4. "unicode"
  5. )
  6. const (
  7. yDefault = "y"
  8. nDefault = "n"
  9. )
  10. // SplitDBFromName split apart db/package to db and package.
  11. func SplitDBFromName(pkg string) (db, name string) {
  12. split := strings.SplitN(pkg, "/", 2)
  13. if len(split) == 2 {
  14. return split[0], split[1]
  15. }
  16. return "", split[0]
  17. }
  18. // LessRunes compares two rune values, and returns true if the first argument is lexicographicaly smaller.
  19. func LessRunes(iRunes, jRunes []rune) bool {
  20. max := len(iRunes)
  21. if max > len(jRunes) {
  22. max = len(jRunes)
  23. }
  24. for idx := 0; idx < max; idx++ {
  25. ir := iRunes[idx]
  26. jr := jRunes[idx]
  27. lir := unicode.ToLower(ir)
  28. ljr := unicode.ToLower(jr)
  29. if lir != ljr {
  30. return lir < ljr
  31. }
  32. // the lowercase runes are the same, so compare the original
  33. if ir != jr {
  34. return ir < jr
  35. }
  36. }
  37. return len(iRunes) < len(jRunes)
  38. }