diff options
Diffstat (limited to 'lld/include/lld/Common/Strings.h')
-rw-r--r-- | lld/include/lld/Common/Strings.h | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/lld/include/lld/Common/Strings.h b/lld/include/lld/Common/Strings.h index 9d002bf336de..3940d2443cd4 100644 --- a/lld/include/lld/Common/Strings.h +++ b/lld/include/lld/Common/Strings.h @@ -27,16 +27,52 @@ bool isValidCIdentifier(llvm::StringRef s); // Write the contents of the a buffer to a file void saveBuffer(llvm::StringRef buffer, const llvm::Twine &path); -// This class represents multiple glob patterns. -class StringMatcher { +// A single pattern to match against. A pattern can either be double-quoted +// text that should be matched exactly after removing the quoting marks or a +// glob pattern in the sense of GlobPattern. +class SingleStringMatcher { public: - StringMatcher() = default; - explicit StringMatcher(llvm::ArrayRef<llvm::StringRef> pat); + // Create a StringPattern from Pattern to be matched exactly irregardless + // of globbing characters if ExactMatch is true. + SingleStringMatcher(llvm::StringRef Pattern); + // Match s against this pattern, exactly if ExactMatch is true. bool match(llvm::StringRef s) const; private: - std::vector<llvm::GlobPattern> patterns; + // Whether to do an exact match irregardless of the presence of wildcard + // character. + bool ExactMatch; + + // GlobPattern object if not doing an exact match. + llvm::GlobPattern GlobPatternMatcher; + + // StringRef to match exactly if doing an exact match. + llvm::StringRef ExactPattern; +}; + +// This class represents multiple patterns to match against. A pattern can +// either be a double-quoted text that should be matched exactly after removing +// the quoted marks or a glob pattern. +class StringMatcher { +private: + // Patterns to match against. + std::vector<SingleStringMatcher> patterns; + +public: + StringMatcher() = default; + + // Matcher for a single pattern. + StringMatcher(llvm::StringRef Pattern) + : patterns({SingleStringMatcher(Pattern)}) {} + + // Add a new pattern to the existing ones to match against. + void addPattern(SingleStringMatcher Matcher) { patterns.push_back(Matcher); } + + bool empty() { return patterns.empty(); } + + // Match s against the patterns. + bool match(llvm::StringRef s) const; }; } // namespace lld |