From 115e175c3d254b3a4797607821a0aab6f08058bb Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Thu, 11 May 2017 20:48:40 +0300 Subject: Change Match to be a function --- match/file.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'match/file.go') diff --git a/match/file.go b/match/file.go index 0b554ce..eee5bec 100644 --- a/match/file.go +++ b/match/file.go @@ -1,26 +1,16 @@ package match -import ( - "strings" -) +import "strings" -// File is a file name Matcher, if the last word can prefix the -// File path, there is a possible match -type File string - -func (a File) String() string { - return string(a) -} - -// Match returns true if prefix's abs path prefixes a's abs path -func (a File) Match(prefix string) bool { +// File returns true if prefix can match the file +func File(file, prefix string) bool { // special case for current directory completion - if a == "./" && (prefix == "." || prefix == "") { + if file == "./" && (prefix == "." || prefix == "") { return true } - cmp := strings.TrimPrefix(string(a), "./") + file = strings.TrimPrefix(file, "./") prefix = strings.TrimPrefix(prefix, "./") - return strings.HasPrefix(cmp, prefix) + return strings.HasPrefix(file, prefix) } -- cgit v1.2.3