2017-07-17 20:19:13 +00:00
|
|
|
package prompt
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
func FilterHasPrefix(completions []string, sub string, ignoreCase bool) []string {
|
|
|
|
if sub == "" {
|
|
|
|
return completions
|
|
|
|
}
|
|
|
|
if ignoreCase {
|
|
|
|
sub = strings.ToUpper(sub)
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := make([]string, 0, len(completions))
|
2017-07-18 02:36:25 +00:00
|
|
|
for i, n := range completions {
|
2017-07-17 20:19:13 +00:00
|
|
|
if ignoreCase {
|
|
|
|
n = strings.ToUpper(n)
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(n, sub) {
|
|
|
|
ret = append(ret, completions[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func FilterHasSuffix(completions []string, sub string, ignoreCase bool) []string {
|
|
|
|
if sub == "" {
|
|
|
|
return completions
|
|
|
|
}
|
|
|
|
if ignoreCase {
|
|
|
|
sub = strings.ToUpper(sub)
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := make([]string, 0, len(completions))
|
2017-07-18 02:36:25 +00:00
|
|
|
for i, n := range completions {
|
2017-07-17 20:19:13 +00:00
|
|
|
if ignoreCase {
|
|
|
|
n = strings.ToUpper(n)
|
|
|
|
}
|
|
|
|
if strings.HasSuffix(n, sub) {
|
|
|
|
ret = append(ret, completions[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func FilterContains(completions []string, sub string, ignoreCase bool) []string {
|
|
|
|
if sub == "" {
|
|
|
|
return completions
|
|
|
|
}
|
|
|
|
if ignoreCase {
|
|
|
|
sub = strings.ToUpper(sub)
|
|
|
|
}
|
|
|
|
|
|
|
|
ret := make([]string, 0, len(completions))
|
2017-07-18 02:36:25 +00:00
|
|
|
for i, n := range completions {
|
2017-07-17 20:19:13 +00:00
|
|
|
if ignoreCase {
|
|
|
|
n = strings.ToUpper(n)
|
|
|
|
}
|
|
|
|
if strings.Contains(n, sub) {
|
2017-07-18 02:36:25 +00:00
|
|
|
ret = append(ret, completions[i])
|
2017-07-17 20:19:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|