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()
28 // No match if `Pattern` ends with a non-meta character not equal to the last in matchFilePath()
30 if (const auto C = Pattern.back(); !strchr("?*]", C) && C != FilePath.back()) in matchFilePath()
34 const auto EOP = Pattern.size(); // End of `Pattern`. in matchFilePath()
36 unsigned I = 0; // Index to `Pattern`. in matchFilePath()
42 switch (const auto F = FilePath[J]; Pattern[I]) { in matchFilePath()
44 if (++I == EOP || F != Pattern[I]) in matchFilePath()
52 while (++I < EOP && Pattern[I] == '*') { // Skip consecutive stars. in matchFilePath()
56 if (I == EOP) // `Pattern` ends with a star. in matchFilePath()
58 // `Pattern` ends with a lone backslash. in matchFilePath()
59 if (Pattern[I] == '\\' && ++I == EOP) in matchFilePath()
62 if (Pattern[I] == Separator) { in matchFilePath()
69 for (auto Pat = Pattern.substr(I); J < End && FilePath[J] != Separator; in matchFilePath()
78 if (I + 3 < EOP || (I + 3 == EOP && Pattern[I + 1] != '!')) { in matchFilePath()
80 if (const auto K = Pattern.find_first_of("]/", I + 1); in matchFilePath()
81 K != StringRef::npos && Pattern[K] == ']' && K > I + 1) { in matchFilePath()
86 if (Pattern[I] == '!') { in matchFilePath()
92 if (I + 2 < K && Pattern[I + 1] == '-') { in matchFilePath()
93 Match = Pattern[I] <= F && F <= Pattern[I + 2]; in matchFilePath()
96 Match = F == Pattern[I++]; in matchFilePath()
107 if (F != Pattern[I]) in matchFilePath()
115 while (I < EOP && Pattern[I] == '*') in matchFilePath()