summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/GlobPattern.cpp
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2025-10-21 16:10:05 -0700
committerVitaly Buka <vitalybuka@google.com>2025-10-21 16:10:05 -0700
commit8a3b8b6b84aa01cc1668ac07deb737f8800588c8 (patch)
treeccd3b5c89a435fa8e71af9e58ff9f6f53085ddb1 /llvm/lib/Support/GlobPattern.cpp
parent8dbc1527f7ad4197dfff8ea598634a8063bb6083 (diff)
[𝘀𝗽𝗿] changes introduced through rebaseusers/vitalybuka/spr/main.globpattern-add-globpatternlongest_substr
Created using spr 1.3.6 [skip ci]
Diffstat (limited to 'llvm/lib/Support/GlobPattern.cpp')
-rw-r--r--llvm/lib/Support/GlobPattern.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/llvm/lib/Support/GlobPattern.cpp b/llvm/lib/Support/GlobPattern.cpp
index 0ecf47dc1d3d..f56a8fcf4bf9 100644
--- a/llvm/lib/Support/GlobPattern.cpp
+++ b/llvm/lib/Support/GlobPattern.cpp
@@ -135,21 +135,24 @@ parseBraceExpansions(StringRef S, std::optional<size_t> MaxSubPatterns) {
Expected<GlobPattern>
GlobPattern::create(StringRef S, std::optional<size_t> MaxSubPatterns) {
GlobPattern Pat;
+ Pat.Pattern = S;
// Store the prefix that does not contain any metacharacter.
- size_t PrefixSize = S.find_first_of("?*[{\\");
- Pat.Prefix = S.substr(0, PrefixSize);
- if (PrefixSize == std::string::npos)
+ Pat.PrefixSize = S.find_first_of("?*[{\\");
+ if (Pat.PrefixSize == std::string::npos) {
+ Pat.PrefixSize = S.size();
return Pat;
- S = S.substr(PrefixSize);
+ }
+ S = S.substr(Pat.PrefixSize);
// Just in case we stop on unmatched opening brackets.
size_t SuffixStart = S.find_last_of("?*[]{}\\");
assert(SuffixStart != std::string::npos);
if (S[SuffixStart] == '\\')
++SuffixStart;
- ++SuffixStart;
- Pat.Suffix = S.substr(SuffixStart);
+ if (SuffixStart < S.size())
+ ++SuffixStart;
+ Pat.SuffixSize = S.size() - SuffixStart;
S = S.substr(0, SuffixStart);
SmallVector<std::string, 1> SubPats;
@@ -200,9 +203,9 @@ GlobPattern::SubGlobPattern::create(StringRef S) {
}
bool GlobPattern::match(StringRef S) const {
- if (!S.consume_front(Prefix))
+ if (!S.consume_front(prefix()))
return false;
- if (!S.consume_back(Suffix))
+ if (!S.consume_back(suffix()))
return false;
if (SubGlobs.empty() && S.empty())
return true;