Lines Matching full:pattern

1 //===--- MatchFilePath.cpp - Match file path with pattern -------*- C++ -*-===//
11 /// a pattern, similar to the POSIX fnmatch() function.
22 // Check whether `FilePath` matches `Pattern` based on POSIX 2.13.1, 2.13.2, and
24 bool matchFilePath(StringRef Pattern, StringRef FilePath) { in matchFilePath() argument
25 assert(!Pattern.empty()); in matchFilePath()
30 // No match if `Pattern` ends with a non-meta character not equal to the last in matchFilePath()
32 if (const auto C = Pattern.back(); !strchr("?*]", C) && C != FilePathBack) in matchFilePath()
36 const auto EOP = Pattern.size(); // End of `Pattern`. in matchFilePath()
38 unsigned I = 0; // Index to `Pattern`. in matchFilePath()
44 switch (const auto F = FilePath[J]; Pattern[I]) { in matchFilePath()
46 if (++I == EOP || F != Pattern[I]) in matchFilePath()
54 bool Globstar = I == 0 || Pattern[I - 1] == Separator; in matchFilePath()
56 for (; ++I < EOP && Pattern[I] == '*'; ++StarCount) { in matchFilePath()
63 if (I == EOP) // `Pattern` ends with a star. in matchFilePath()
65 if (Pattern[I] != Separator) { in matchFilePath()
66 // `Pattern` ends with a lone backslash. in matchFilePath()
67 if (Pattern[I] == '\\' && ++I == EOP) in matchFilePath()
72 if (Pattern[I] == Separator) { in matchFilePath()
83 for (auto Pat = Pattern.substr(I); in matchFilePath()
92 if (I + 3 < EOP || (I + 3 == EOP && Pattern[I + 1] != '!')) { in matchFilePath()
94 if (const auto K = Pattern.find_first_of("]/", I + 1); in matchFilePath()
95 K != StringRef::npos && Pattern[K] == ']' && K > I + 1) { in matchFilePath()
100 if (Pattern[I] == '!') { in matchFilePath()
106 if (I + 2 < K && Pattern[I + 1] == '-') { in matchFilePath()
107 Match = Pattern[I] <= F && F <= Pattern[I + 2]; in matchFilePath()
110 Match = F == Pattern[I++]; in matchFilePath()
121 if (F != Pattern[I]) in matchFilePath()
129 while (I < EOP && Pattern[I] == '*') in matchFilePath()