From 6fb4875efa1f536813da29972a0c3250bde8b5eb Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Sun, 7 May 2017 19:53:55 +0300 Subject: Move match to a separate package --- match.go | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 match.go (limited to 'match.go') diff --git a/match.go b/match.go deleted file mode 100644 index 8da8f2c..0000000 --- a/match.go +++ /dev/null @@ -1,50 +0,0 @@ -package complete - -import ( - "path/filepath" - "strings" -) - -// Matcher matches itself to a string -// it is used for comparing a given argument to the last typed -// word, and see if it is a possible auto complete option. -type Matcher interface { - String() string - Match(prefix string) bool -} - -// MatchPrefix is a simple Matcher, if the word is it's prefix, there is a match -type MatchPrefix string - -func (a MatchPrefix) String() string { - return string(a) -} - -// Match returns true if a has the prefix as prefix -func (a MatchPrefix) Match(prefix string) bool { - return strings.HasPrefix(string(a), prefix) -} - -// MatchFileName is a file name Matcher, if the last word can prefix the -// MatchFileName path, there is a possible match -type MatchFileName string - -func (a MatchFileName) String() string { - return string(a) -} - -// Match returns true if prefix's abs path prefixes a's abs path -func (a MatchFileName) Match(prefix string) bool { - full, err := filepath.Abs(string(a)) - if err != nil { - Log("failed getting abs path of %s: %s", a, err) - } - prefixFull, err := filepath.Abs(prefix) - if err != nil { - Log("failed getting abs path of %s: %s", prefix, err) - } - - // if the file has the prefix as prefix, - // but we don't want to show too many files, so, if it is in a deeper directory - omit it. - return strings.HasPrefix(full, prefixFull) && (full == prefixFull || !strings.Contains(full[len(prefixFull)+1:], "/")) -} -- cgit v1.2.3