|
|
|||
File indexing completed on 2026-05-10 08:42:41
0001 //===- Strings.h ------------------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLD_STRINGS_H 0010 #define LLD_STRINGS_H 0011 0012 #include "llvm/ADT/ArrayRef.h" 0013 #include "llvm/ADT/SmallVector.h" 0014 #include "llvm/ADT/StringRef.h" 0015 #include "llvm/Support/GlobPattern.h" 0016 #include <string> 0017 #include <vector> 0018 0019 namespace lld { 0020 0021 llvm::SmallVector<uint8_t, 0> parseHex(llvm::StringRef s); 0022 bool isValidCIdentifier(llvm::StringRef s); 0023 0024 // Write the contents of the a buffer to a file 0025 void saveBuffer(llvm::StringRef buffer, const llvm::Twine &path); 0026 0027 // A single pattern to match against. A pattern can either be double-quoted 0028 // text that should be matched exactly after removing the quoting marks or a 0029 // glob pattern in the sense of GlobPattern. 0030 class SingleStringMatcher { 0031 public: 0032 // Create a StringPattern from Pattern to be matched exactly regardless 0033 // of globbing characters if ExactMatch is true. 0034 SingleStringMatcher(llvm::StringRef Pattern); 0035 0036 // Match s against this pattern, exactly if ExactMatch is true. 0037 bool match(llvm::StringRef s) const; 0038 0039 // Returns true for pattern "*" which will match all inputs. 0040 bool isTrivialMatchAll() const { 0041 return !ExactMatch && GlobPatternMatcher.isTrivialMatchAll(); 0042 } 0043 0044 private: 0045 // Whether to do an exact match regardless of wildcard characters. 0046 bool ExactMatch; 0047 0048 // GlobPattern object if not doing an exact match. 0049 llvm::GlobPattern GlobPatternMatcher; 0050 0051 // StringRef to match exactly if doing an exact match. 0052 llvm::StringRef ExactPattern; 0053 }; 0054 0055 // This class represents multiple patterns to match against. A pattern can 0056 // either be a double-quoted text that should be matched exactly after removing 0057 // the quoted marks or a glob pattern. 0058 class StringMatcher { 0059 private: 0060 // Patterns to match against. 0061 std::vector<SingleStringMatcher> patterns; 0062 0063 public: 0064 StringMatcher() = default; 0065 0066 // Matcher for a single pattern. 0067 StringMatcher(llvm::StringRef Pattern) 0068 : patterns({SingleStringMatcher(Pattern)}) {} 0069 0070 // Add a new pattern to the existing ones to match against. 0071 void addPattern(SingleStringMatcher Matcher) { patterns.push_back(Matcher); } 0072 0073 bool empty() const { return patterns.empty(); } 0074 0075 // Match s against the patterns. 0076 bool match(llvm::StringRef s) const; 0077 }; 0078 0079 } // namespace lld 0080 0081 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|