[llvm-branch-commits] [llvm] [NFC][Support] Define Prefix/SuffixMetacharacters constants (PR #202850)

Vitaly Buka via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jun 9 22:25:06 PDT 2026


https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/202850

>From ab2ac13213557fadfd9748832dc7444f357e621e Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 9 Jun 2026 21:55:07 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.7
---
 llvm/lib/Support/GlobPattern.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

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;



More information about the llvm-branch-commits mailing list