Revert "Move suggest filters to github.com/c-bata/filter package"
This reverts commit 2c70a30e59
.
This commit is contained in:
parent
2c70a30e59
commit
f119db91a1
|
@ -20,7 +20,6 @@
|
|||
|
||||
* SetColor method in ConsoleWriter is deprecated. Please use SetDisplayAttributes instead.
|
||||
* prompt.Choose shortcut function is deprecated.
|
||||
* FilterHasPrefix, FilterHasSuffix and FilterContains is deprecated. Move to "github.com/c-bata/go-prompt/filter" package.
|
||||
|
||||
## v0.2.1 (2018/02/14)
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package prompt
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
import "strings"
|
||||
|
||||
// Filter is the type to filter the prompt.Suggestion array.
|
||||
// Deprecated, move to github.com/c-bata/go-prompt/filter package.
|
||||
type Filter func([]Suggest, string, bool) []Suggest
|
||||
|
||||
// FilterHasPrefix checks whether the string completions.Text begins with sub.
|
||||
// Deprecated, move to github.com/c-bata/go-prompt/filter package.
|
||||
func FilterHasPrefix(completions []Suggest, sub string, ignoreCase bool) []Suggest {
|
||||
if sub == "" {
|
||||
return completions
|
||||
|
@ -32,7 +28,6 @@ func FilterHasPrefix(completions []Suggest, sub string, ignoreCase bool) []Sugge
|
|||
}
|
||||
|
||||
// FilterHasSuffix checks whether the completion.Text ends with sub.
|
||||
// Deprecated, move to github.com/c-bata/go-prompt/filter package.
|
||||
func FilterHasSuffix(completions []Suggest, sub string, ignoreCase bool) []Suggest {
|
||||
if sub == "" {
|
||||
return completions
|
||||
|
@ -55,7 +50,6 @@ func FilterHasSuffix(completions []Suggest, sub string, ignoreCase bool) []Sugge
|
|||
}
|
||||
|
||||
// FilterContains checks whether the completion.Text contains sub.
|
||||
// Deprecated, move to github.com/c-bata/go-prompt/filter package.
|
||||
func FilterContains(completions []Suggest, sub string, ignoreCase bool) []Suggest {
|
||||
if sub == "" {
|
||||
return completions
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
package filter
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/c-bata/go-prompt"
|
||||
)
|
||||
|
||||
// HasPrefix checks whether the string completions.Text begins with sub.
|
||||
func HasPrefix(suggests []prompt.Suggest, sub string, ignoreCase bool) []prompt.Suggest {
|
||||
if sub == "" {
|
||||
return suggests
|
||||
}
|
||||
if ignoreCase {
|
||||
sub = strings.ToUpper(sub)
|
||||
}
|
||||
|
||||
ret := make([]prompt.Suggest, 0, len(suggests))
|
||||
for i := range suggests {
|
||||
c := suggests[i].Text
|
||||
if ignoreCase {
|
||||
c = strings.ToUpper(c)
|
||||
}
|
||||
if strings.HasPrefix(c, sub) {
|
||||
ret = append(ret, suggests[i])
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// HasSuffix checks whether the completion.Text ends with sub.
|
||||
func HasSuffix(suggests []prompt.Suggest, sub string, ignoreCase bool) []prompt.Suggest {
|
||||
if sub == "" {
|
||||
return suggests
|
||||
}
|
||||
if ignoreCase {
|
||||
sub = strings.ToUpper(sub)
|
||||
}
|
||||
|
||||
ret := make([]prompt.Suggest, 0, len(suggests))
|
||||
for i := range suggests {
|
||||
c := suggests[i].Text
|
||||
if ignoreCase {
|
||||
c = strings.ToUpper(c)
|
||||
}
|
||||
if strings.HasSuffix(c, sub) {
|
||||
ret = append(ret, suggests[i])
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Contains checks whether the completion.Text contains sub.
|
||||
func Contains(suggests []prompt.Suggest, sub string, ignoreCase bool) []prompt.Suggest {
|
||||
if sub == "" {
|
||||
return suggests
|
||||
}
|
||||
if ignoreCase {
|
||||
sub = strings.ToUpper(sub)
|
||||
}
|
||||
|
||||
ret := make([]prompt.Suggest, 0, len(suggests))
|
||||
for i := range suggests {
|
||||
c := suggests[i].Text
|
||||
if ignoreCase {
|
||||
c = strings.ToUpper(c)
|
||||
}
|
||||
if strings.Contains(c, sub) {
|
||||
ret = append(ret, suggests[i])
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
Loading…
Reference in New Issue