yay/pkg/text/text.go

50 lines
860 B
Go
Raw Normal View History

2020-07-10 00:36:45 +00:00
package text
import (
"strings"
"unicode"
)
const (
yDefault = "y"
nDefault = "n"
)
2021-08-11 18:13:28 +00:00
// SplitDBFromName split apart db/package to db and package.
2020-07-10 00:36:45 +00:00
func SplitDBFromName(pkg string) (db, name string) {
split := strings.SplitN(pkg, "/", 2)
if len(split) == 2 {
return split[0], split[1]
}
2021-08-11 18:13:28 +00:00
2020-07-10 00:36:45 +00:00
return "", split[0]
}
// LessRunes compares two rune values, and returns true if the first argument is lexicographicaly smaller.
func LessRunes(iRunes, jRunes []rune) bool {
max := len(iRunes)
if max > len(jRunes) {
max = len(jRunes)
}
for idx := 0; idx < max; idx++ {
ir := iRunes[idx]
jr := jRunes[idx]
lir := unicode.ToLower(ir)
ljr := unicode.ToLower(jr)
if lir != ljr {
return lir < ljr
}
// the lowercase runes are the same, so compare the original
if ir != jr {
return ir < jr
}
}
return len(iRunes) < len(jRunes)
}