@@ -188,7 +188,7 @@ struct StructureElement {
188
188
:StructureNode(StructureNode), ASTNode(ASTNode) { }
189
189
};
190
190
191
- static const std::vector<std::string> URLPro = {
191
+ static const std::vector<std::string> URLProtocols = {
192
192
193
193
// Use RegexStrURL:
194
194
" acap" , " afp" , " afs" , " cid" , " data" , " fax" , " feed" , " file" , " ftp" , " go" ,
@@ -234,26 +234,11 @@ class ModelASTWalker : public ASTWalker {
234
234
unsigned BufferID;
235
235
std::vector<StructureElement> SubStructureStack;
236
236
SourceLoc LastLoc;
237
- std::regex URLRxs[3 ] = {
238
- std::regex{ RegexStrURL, std::regex::ECMAScript | std::regex::nosubs },
239
- std::regex{ RegexStrMailURL, std::regex::ECMAScript | std::regex::nosubs },
240
- std::regex{ RegexStrRadarURL, std::regex::ECMAScript | std::regex::nosubs }};
241
-
242
- std::regex DocCommentRxs[3 ] = {
243
- std::regex {
244
- RegexStrParameter,
245
- std::regex::egrep | std::regex::icase | std::regex::optimize
246
- },
247
- std::regex {
248
- RegexStrDocCommentParametersHeading,
249
- std::regex::egrep | std::regex::icase | std::regex::optimize
250
- },
251
- std::regex { RegexStrDocCommentField,
252
- std::regex::egrep | std::regex::icase | std::regex::optimize
253
- }
254
- };
237
+ static const std::regex URLRxs[3 ];
238
+ static const std::regex DocCommentRxs[3 ];
255
239
256
- Optional<SyntaxNode> parseFieldNode (StringRef Text, StringRef OrigText, SourceLoc OrigLoc);
240
+ Optional<SyntaxNode> parseFieldNode (StringRef Text, StringRef OrigText,
241
+ SourceLoc OrigLoc);
257
242
258
243
public:
259
244
SyntaxModelWalker &Walker;
@@ -276,7 +261,8 @@ class ModelASTWalker : public ASTWalker {
276
261
bool shouldWalkIntoFunctionGenericParams () override { return true ; }
277
262
278
263
private:
279
- bool findUrlStartingLoc (StringRef Text, unsigned &Start, std::regex& Regex);
264
+ static bool findUrlStartingLoc (StringRef Text, unsigned &Start,
265
+ std::regex& Regex);
280
266
bool annotateIfConfigConditionIdentifiers (Expr *Cond);
281
267
bool handleAttrs (const DeclAttributes &Attrs);
282
268
bool handleAttrs (const TypeAttributes &Attrs);
@@ -308,6 +294,27 @@ class ModelASTWalker : public ASTWalker {
308
294
bool findFieldsInDocCommentBlock (SyntaxNode Node);
309
295
};
310
296
297
+ const std::regex ModelASTWalker::URLRxs[3 ] = {
298
+ std::regex{ RegexStrURL, std::regex::ECMAScript | std::regex::nosubs },
299
+ std::regex{ RegexStrMailURL, std::regex::ECMAScript | std::regex::nosubs },
300
+ std::regex{ RegexStrRadarURL, std::regex::ECMAScript | std::regex::nosubs }
301
+ };
302
+
303
+ const std::regex ModelASTWalker::DocCommentRxs[3 ] = {
304
+ std::regex {
305
+ RegexStrParameter,
306
+ std::regex::egrep | std::regex::icase | std::regex::optimize
307
+ },
308
+ std::regex {
309
+ RegexStrDocCommentParametersHeading,
310
+ std::regex::egrep | std::regex::icase | std::regex::optimize
311
+ },
312
+ std::regex {
313
+ RegexStrDocCommentField,
314
+ std::regex::egrep | std::regex::icase | std::regex::optimize
315
+ }
316
+ };
317
+
311
318
SyntaxStructureKind syntaxStructureKindFromNominalTypeDecl (NominalTypeDecl *N) {
312
319
if (isa<ClassDecl>(N))
313
320
return SyntaxStructureKind::Class;
@@ -1179,24 +1186,27 @@ bool ModelASTWalker::processComment(CharSourceRange Range) {
1179
1186
bool ModelASTWalker::findUrlStartingLoc (StringRef Text,
1180
1187
unsigned &Start,
1181
1188
std::regex &Regex) {
1182
- static const auto MailToPosition = std::find (URLPro.begin (), URLPro.end (),
1189
+ static const auto MailToPosition = std::find (URLProtocols.begin (),
1190
+ URLProtocols.end (),
1183
1191
" mailto" );
1184
- static const auto RadarPosition = std::find (URLPro.begin (), URLPro.end (),
1192
+ static const auto RadarPosition = std::find (URLProtocols.begin (),
1193
+ URLProtocols.end (),
1185
1194
" radar" );
1186
- auto Index = Text.find (" ://" );
1187
- if (Index != StringRef::npos) {
1188
- for (auto It = URLPro.begin (); It != URLPro.end (); ++ It) {
1189
- if (Index >= It->size () &&
1190
- Text.substr (Index - It->size (), It->size ()) == *It) {
1191
- Start = Index - It->size ();
1192
- if (It < MailToPosition)
1193
- Regex = URLRxs[0 ];
1194
- else if (It < RadarPosition)
1195
- Regex = URLRxs[1 ];
1196
- else
1197
- Regex = URLRxs[2 ];
1198
- return true ;
1199
- }
1195
+ auto Index = Text.find (" :" );
1196
+ if (Index == StringRef::npos)
1197
+ return false ;
1198
+
1199
+ for (auto It = URLProtocols.begin (); It != URLProtocols.end (); ++ It) {
1200
+ if (Index >= It->size () &&
1201
+ Text.substr (Index - It->size (), It->size ()) == *It) {
1202
+ Start = Index - It->size ();
1203
+ if (It < MailToPosition)
1204
+ Regex = URLRxs[0 ];
1205
+ else if (It < RadarPosition)
1206
+ Regex = URLRxs[1 ];
1207
+ else
1208
+ Regex = URLRxs[2 ];
1209
+ return true ;
1200
1210
}
1201
1211
}
1202
1212
return false ;
@@ -1209,7 +1219,7 @@ bool ModelASTWalker::searchForURL(CharSourceRange Range) {
1209
1219
StringRef Text = OrigText;
1210
1220
while (1 ) {
1211
1221
std::match_results<StringRef::iterator> Matches;
1212
- std::regex & Regex = URLRxs[ 0 ] ;
1222
+ std::regex Regex;
1213
1223
unsigned Start;
1214
1224
if (findUrlStartingLoc (Text, Start, Regex) &&
1215
1225
std::regex_search (Text.substr (Start).begin (),
0 commit comments