diff options
| author | Eyal Posener <[email protected]> | 2019-07-05 17:33:47 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-07-05 17:33:47 +0300 |
| commit | 2f2ff270a9f6adcef8351b1bdf5319b5d612b53f (patch) | |
| tree | 0dbc83883d33ac239db651f19be3fe67fd3dc361 /match/match.go | |
| parent | 6ffe496ea9530c0638974624ed9dd429f9ad592e (diff) | |
| parent | 72c5c945f0d5861ba1d4e51a0a5ac36a4bef3868 (diff) | |
Merge pull request #98 from posener/refactor
Some refactorings
Diffstat (limited to 'match/match.go')
| -rw-r--r-- | match/match.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/match/match.go b/match/match.go index b9c0973..b5f1814 100644 --- a/match/match.go +++ b/match/match.go @@ -1,7 +1,39 @@ // Package match contains matchers that decide if to apply completion. +// +// This package is deprecated. package match +import "strings" + // 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. +// +// Deprecated. type Match func(term, prefix string) bool + +// 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) +} |
