github.com/gechr/complete@v0.0.0-20191016221035-401475e3ce1e/match/match.go (about)

     1  // Package match contains matchers that decide if to apply completion.
     2  //
     3  // This package is deprecated.
     4  package match
     5  
     6  import "strings"
     7  
     8  // Match matches two strings
     9  // it is used for comparing a term to the last typed
    10  // word, the prefix, and see if it is a possible auto complete option.
    11  //
    12  // Deprecated.
    13  type Match func(term, prefix string) bool
    14  
    15  // Prefix is a simple Matcher, if the word is it's prefix, there is a match
    16  // Match returns true if a has the prefix as prefix
    17  //
    18  // Deprecated.
    19  func Prefix(long, prefix string) bool {
    20  	return strings.HasPrefix(long, prefix)
    21  }
    22  
    23  // File returns true if prefix can match the file
    24  //
    25  // Deprecated.
    26  func File(file, prefix string) bool {
    27  	// special case for current directory completion
    28  	if file == "./" && (prefix == "." || prefix == "") {
    29  		return true
    30  	}
    31  	if prefix == "." && strings.HasPrefix(file, ".") {
    32  		return true
    33  	}
    34  
    35  	file = strings.TrimPrefix(file, "./")
    36  	prefix = strings.TrimPrefix(prefix, "./")
    37  
    38  	return strings.HasPrefix(file, prefix)
    39  }