@@ -135,21 +135,24 @@ parseBraceExpansions(StringRef S, std::optional<size_t> MaxSubPatterns) {
135135Expected<GlobPattern>
136136GlobPattern::create (StringRef S, std::optional<size_t > MaxSubPatterns) {
137137 GlobPattern Pat;
138+ Pat.Pattern = S;
138139
139140 // Store the prefix that does not contain any metacharacter.
140- size_t PrefixSize = S.find_first_of (" ?*[{\\ " );
141- Pat.Prefix = S. substr ( 0 , PrefixSize);
142- if ( PrefixSize == std::string::npos)
141+ Pat. PrefixSize = S.find_first_of (" ?*[{\\ " );
142+ if ( Pat.PrefixSize == std::string::npos) {
143+ Pat. PrefixSize = S. size ();
143144 return Pat;
144- S = S.substr (PrefixSize);
145+ }
146+ S = S.substr (Pat.PrefixSize );
145147
146148 // Just in case we stop on unmatched opening brackets.
147149 size_t SuffixStart = S.find_last_of (" ?*[]{}\\ " );
148150 assert (SuffixStart != std::string::npos);
149151 if (S[SuffixStart] == ' \\ ' )
150152 ++SuffixStart;
151- ++SuffixStart;
152- Pat.Suffix = S.substr (SuffixStart);
153+ if (SuffixStart < S.size ())
154+ ++SuffixStart;
155+ Pat.SuffixSize = S.size () - SuffixStart;
153156 S = S.substr (0 , SuffixStart);
154157
155158 SmallVector<std::string, 1 > SubPats;
@@ -200,9 +203,9 @@ GlobPattern::SubGlobPattern::create(StringRef S) {
200203}
201204
202205bool GlobPattern::match (StringRef S) const {
203- if (!S.consume_front (Prefix ))
206+ if (!S.consume_front (prefix () ))
204207 return false ;
205- if (!S.consume_back (Suffix ))
208+ if (!S.consume_back (suffix () ))
206209 return false ;
207210 if (SubGlobs.empty () && S.empty ())
208211 return true ;
0 commit comments