[llvm] [NFC][Support] Define Prefix/SuffixMetacharacters constants (PR #202850)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 9 21:55:51 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Vitaly Buka (vitalybuka)
<details>
<summary>Changes</summary>
Extract literal metacharacter strings used in GlobPattern into static constexpr arrays to improve consistency and maintainability.
Assisted-by: Gemini
---
Full diff: https://github.com/llvm/llvm-project/pull/202850.diff
1 Files Affected:
- (modified) llvm/lib/Support/GlobPattern.cpp (+6-3)
``````````diff
diff --git a/llvm/lib/Support/GlobPattern.cpp b/llvm/lib/Support/GlobPattern.cpp
index 2715229c65be1..6ed3b77d32be1 100644
--- a/llvm/lib/Support/GlobPattern.cpp
+++ b/llvm/lib/Support/GlobPattern.cpp
@@ -16,6 +16,9 @@
using namespace llvm;
+static constexpr char PrefixMetacharacters[] = "?*[{\\";
+static constexpr char SuffixMetacharacters[] = "?*[]{}\\";
+
// Expands character ranges and returns a bitmap.
// For example, "a-cf-hz" is expanded to "abcfghz".
static Expected<BitVector> expand(StringRef S, StringRef Original) {
@@ -135,7 +138,7 @@ parseBraceExpansions(StringRef S, std::optional<size_t> MaxSubPatterns) {
static StringRef maxPlainSubstring(StringRef S) {
StringRef Best;
while (!S.empty()) {
- size_t PrefixSize = S.find_first_of("?*[{\\");
+ size_t PrefixSize = S.find_first_of(PrefixMetacharacters);
if (PrefixSize == std::string::npos)
PrefixSize = S.size();
@@ -181,7 +184,7 @@ GlobPattern::create(StringRef S, std::optional<size_t> MaxSubPatterns) {
Pat.Pattern = S;
// Store the prefix that does not contain any metacharacter.
- Pat.PrefixSize = S.find_first_of("?*[{\\");
+ Pat.PrefixSize = S.find_first_of(PrefixMetacharacters);
if (Pat.PrefixSize == std::string::npos) {
Pat.PrefixSize = S.size();
return Pat;
@@ -189,7 +192,7 @@ GlobPattern::create(StringRef S, std::optional<size_t> MaxSubPatterns) {
S = S.substr(Pat.PrefixSize);
// Just in case we stop on unmatched opening brackets.
- size_t SuffixStart = S.find_last_of("?*[]{}\\");
+ size_t SuffixStart = S.find_last_of(SuffixMetacharacters);
assert(SuffixStart != std::string::npos);
if (S[SuffixStart] == '\\')
++SuffixStart;
``````````
</details>
https://github.com/llvm/llvm-project/pull/202850
More information about the llvm-commits
mailing list