complete/match/match.go

40 lines
1003 B
Go
Raw Normal View History

2019-03-08 01:25:01 -06:00
// Package match contains matchers that decide if to apply completion.
2019-07-05 06:58:49 -05:00
//
// This package is deprecated.
2017-05-07 11:53:55 -05:00
package match
2019-07-05 06:58:49 -05:00
import "strings"
2017-05-11 12:48:40 -05:00
// Match matches two strings
// it is used for comparing a term to the last typed
// word, the prefix, and see if it is a possible auto complete option.
2019-07-05 06:58:49 -05:00
//
// Deprecated.
2017-05-11 12:48:40 -05:00
type Match func(term, prefix string) bool
2019-07-05 06:58:49 -05:00
// Prefix is a simple Matcher, if the word is it's prefix, there is a match
// Match returns true if a has the prefix as prefix
//
// Deprecated.
func Prefix(long, prefix string) bool {
return strings.HasPrefix(long, prefix)
}
// File returns true if prefix can match the file
//
// Deprecated.
func File(file, prefix string) bool {
// special case for current directory completion
if file == "./" && (prefix == "." || prefix == "") {
return true
}
if prefix == "." && strings.HasPrefix(file, ".") {
return true
}
file = strings.TrimPrefix(file, "./")
prefix = strings.TrimPrefix(prefix, "./")
return strings.HasPrefix(file, prefix)
}