17
17
18
18
#include < QTextEdit>
19
19
#include < QProgressBar>
20
- #include < QDesktopWidget>
21
20
#include < QFileDialog>
22
21
#include < QUrl>
22
+ #include < QRegularExpression>
23
23
#if QT_VERSION >= 0x050000
24
24
#include < QStandardPaths>
25
25
#else
@@ -213,139 +213,136 @@ void CheckerWindow::create_parsespeed_options(QString& parsespeed)
213
213
// ---------------------------------------------------------------------------
214
214
void CheckerWindow::add_policy_to_html_selection (QString& policies, QString& html, const QString& selector)
215
215
{
216
- QRegExp reg (" class=\" policyList form-control\" >" );
216
+ QRegularExpression reg (" class=\" policyList form-control\" >" , QRegularExpression::InvertedGreedinessOption );
217
217
int pos = html.indexOf (selector);
218
218
219
- reg.setMinimal (true );
220
-
221
219
if (pos == -1 )
222
220
return ;
223
221
224
- if ((pos = reg.indexIn (html, pos)) != -1 )
222
+ QRegularExpressionMatch match = reg.match (html, pos);
223
+ if ((pos = match.capturedStart ()) != -1 )
225
224
{
226
- pos += reg. matchedLength ();
225
+ pos += match. capturedLength ();
227
226
html.insert (pos, policies);
228
227
}
229
228
}
230
229
231
230
// ---------------------------------------------------------------------------
232
231
void CheckerWindow::add_display_to_html_selection (QString& displays, QString& html, const QString& selector)
233
232
{
234
- QRegExp reg (" class=\" displayList form-control\" >" );
235
- reg.setMinimal (true );
233
+ QRegularExpression reg (" class=\" displayList form-control\" >" , QRegularExpression::InvertedGreedinessOption);
236
234
237
235
int pos = html.indexOf (selector);
238
236
if (pos == -1 )
239
237
return ;
240
238
241
- if ((pos = reg.indexIn (html, pos)) != -1 )
239
+ QRegularExpressionMatch match = reg.match (html, pos);
240
+ if ((pos = match.capturedStart ()) != -1 )
242
241
{
243
- pos += reg. matchedLength ();
242
+ pos += match. capturedLength ();
244
243
html.insert (pos, displays);
245
244
}
246
245
}
247
246
248
247
// ---------------------------------------------------------------------------
249
248
void CheckerWindow::add_verbosity_to_html_selection (QString& verbosity, QString& html, const QString& selector)
250
249
{
251
- QRegExp reg (" class=\" verbosityList form-control\" >" );
252
- reg.setMinimal (true );
250
+ QRegularExpression reg (" class=\" verbosityList form-control\" >" , QRegularExpression::InvertedGreedinessOption);
253
251
254
252
int pos = html.indexOf (selector);
255
253
if (pos == -1 )
256
254
return ;
257
255
258
- if ((pos = reg.indexIn (html, pos)) != -1 )
256
+ QRegularExpressionMatch match = reg.match (html, pos);
257
+ if ((pos = match.capturedStart ()) != -1 )
259
258
{
260
- pos += reg. matchedLength ();
259
+ pos += match. capturedLength ();
261
260
html.insert (pos, verbosity);
262
261
}
263
262
}
264
263
265
264
// ---------------------------------------------------------------------------
266
265
void CheckerWindow::add_parsespeed_to_html_selection (QString& parsespeed, QString& html, const QString& selector)
267
266
{
268
- QRegExp reg (" class=\" parsespeedList form-control\" >" );
269
- reg.setMinimal (true );
267
+ QRegularExpression reg (" class=\" parsespeedList form-control\" >" , QRegularExpression::InvertedGreedinessOption);
270
268
271
269
int pos = html.indexOf (selector);
272
270
if (pos == -1 )
273
271
return ;
274
272
275
- if ((pos = reg.indexIn (html, pos)) != -1 )
273
+ QRegularExpressionMatch match = reg.match (html, pos);
274
+ if ((pos = match.capturedStart ()) != -1 )
276
275
{
277
- pos += reg. matchedLength ();
276
+ pos += match. capturedLength ();
278
277
html.insert (pos, parsespeed);
279
278
}
280
279
}
281
280
282
281
// ---------------------------------------------------------------------------
283
282
void CheckerWindow::load_include_in_template (QString& html)
284
283
{
285
- QRegExp reg (" \\ {\\ {[\\ s]+include\\ ('AppBundle:(\\ w+):(\\ w+).html.twig'(,[\\ s]*\\ { '\\ w+':[\\ s]*\\ w+[\\ s]*\\ })?\\ )[\\ s]\\ }\\ }" );
284
+ QRegularExpression reg (" \\ {\\ {[\\ s]+include\\ ('AppBundle:(\\ w+):(\\ w+).html.twig'(,[\\ s]*\\ { '\\ w+':[\\ s]*\\ w+[\\ s]*\\ })?\\ )[\\ s]\\ }\\ }" );
285
+ QRegularExpressionMatch match;
286
286
int pos = 0 ;
287
287
288
- while ((pos = reg.indexIn (html, pos)) != -1 )
288
+ while ((pos = (match = reg.match (html, pos)). capturedStart ( )) != -1 )
289
289
{
290
- QString app = reg. cap (1 );
291
- QString module = reg. cap (2 );
290
+ QString app = match. captured (1 );
291
+ QString module = match. captured (2 );
292
292
if (app == " Default" && module == " quotaExceeded" )
293
293
{
294
- html.replace (pos, reg. matchedLength (), " " );
294
+ html.replace (match. capturedStart (), match. capturedLength (), " " );
295
295
continue ;
296
296
}
297
- html.replace (pos, reg. matchedLength (), " " );
297
+ html.replace (match. capturedStart (), match. capturedLength (), " " );
298
298
pos = 0 ;
299
299
}
300
300
}
301
301
302
302
// ---------------------------------------------------------------------------
303
303
void CheckerWindow::remove_element_in_template (QString& html)
304
304
{
305
- QRegExp reg (" \\ {% (.*) %\\ }" );
306
- int pos = 0 ;
307
-
308
- reg.setMinimal (true );
309
- while ((pos = reg.indexIn (html, pos)) != -1 )
310
- html.replace (pos, reg.matchedLength (), " " );
305
+ QRegularExpression reg (" \\ {% (.*) %\\ }" , QRegularExpression::InvertedGreedinessOption);
306
+ html.replace (reg, " " );
311
307
}
312
308
313
309
// ---------------------------------------------------------------------------
314
310
void CheckerWindow::change_collapse_form (QString& html)
315
311
{
316
- QRegExp reg (" class=\" panel-collapse collapse in\" " );
317
- int pos = 0 ;
318
-
319
- while ((pos = reg.indexIn (html, pos)) != -1 )
320
- html.replace (pos, reg.matchedLength (), " class=\" panel-collapse collapse\" " );
312
+ QRegularExpression reg (" class=\" panel-collapse collapse in\" " );
313
+ html.replace (reg, " class=\" panel-collapse collapse\" " );
321
314
}
322
315
323
316
// ---------------------------------------------------------------------------
324
317
void CheckerWindow::load_form_in_template (QString& html)
325
318
{
326
- QRegExp reg (" \\ {\\ {[\\ s]+form\\ ((\\ w+)\\ )[\\ s]\\ }\\ }" );
327
- int pos = 0 ;
319
+ QRegularExpression reg (" \\ {\\ {[\\ s]+form\\ ((\\ w+)\\ )[\\ s]\\ }\\ }" );
320
+ QRegularExpressionMatch match ;
328
321
329
322
bool has_libcurl = main_window->mil_has_curl_enabled ();
330
- while ((pos = reg.indexIn (html, pos)) != -1 )
323
+
324
+ int pos = 0 ;
325
+ while ((pos = (match = reg.match (html)).capturedStart ()) != -1 )
331
326
{
332
- QString value = reg. cap (1 );
327
+ QString value = match. captured (1 );
333
328
if (value == " formUpload" )
334
- html.replace (pos, reg.matchedLength (), create_form_upload ());
329
+ {
330
+ html.replace (match.capturedStart (), match.capturedLength (), create_form_upload ());
331
+ }
335
332
else if (value == " formOnline" )
336
333
{
337
334
if (has_libcurl)
338
- html.replace (pos, reg. matchedLength (), create_form_online ());
335
+ html.replace (match. capturedStart (), match. capturedLength (), create_form_online ());
339
336
else
340
337
{
341
338
remove_form_online (pos, html);
342
- remove_li_online (pos, html);
339
+ remove_li_online (html);
343
340
}
344
341
}
345
342
else if (value == " formRepository" )
346
- html.replace (pos, reg. matchedLength (), create_form_repository ());
343
+ html.replace (match. capturedStart (), match. capturedLength (), create_form_repository ());
347
344
else
348
- html.replace (pos, reg. matchedLength (), " " );
345
+ html.replace (match. capturedStart (), match. capturedLength (), " " );
349
346
}
350
347
351
348
change_collapse_form (html);
@@ -413,40 +410,31 @@ QString CheckerWindow::create_form_online()
413
410
void CheckerWindow::remove_form_online (int pos, QString& html)
414
411
{
415
412
int start_div_pos = pos;
416
- QRegExp reg (" <div role=\" tabpanel\" class=\" tab-pane panel col-md-12\" id=\" url\" >" );
417
- reg.setMinimal (true );
418
- start_div_pos = reg.lastIndexIn (html, start_div_pos);
413
+ start_div_pos = html.lastIndexOf (" <div role=\" tabpanel\" class=\" tab-pane panel col-md-12\" id=\" url\" >" , start_div_pos);
419
414
420
- reg = QRegExp (" </div>" );
421
- reg.setMinimal (true );
422
- int end_div_pos = pos;
423
- if ((end_div_pos = reg.indexIn (html, end_div_pos)) != -1 )
424
- end_div_pos += reg.matchedLength ();
415
+ int end_div_pos = html.indexOf (" </div>" , start_div_pos);
416
+ if (end_div_pos != -1 )
417
+ end_div_pos += 6 ;
425
418
426
419
if (end_div_pos != -1 && start_div_pos != -1 )
427
420
html.remove (start_div_pos, end_div_pos - start_div_pos);
428
421
}
429
422
430
423
// ---------------------------------------------------------------------------
431
- void CheckerWindow::remove_li_online (int & pos, QString& html)
424
+ void CheckerWindow::remove_li_online (QString& html)
432
425
{
433
- QRegExp reg (" <li role=\" presentation\" class=\"\" ><a href=\" #url\" " );
434
- reg.setMinimal (true );
435
- int start = reg.lastIndexIn (html);
426
+ int start = html.lastIndexOf (" <li role=\" presentation\" class=\"\" ><a href=\" #url\" " );
436
427
if (start == -1 )
437
428
return ;
438
429
439
- reg = QRegExp (" </li>" );
440
- reg.setMinimal (true );
441
- int end_pos = -1 ;
442
- if ((end_pos = reg.indexIn (html, start)) != -1 )
443
- end_pos += reg.matchedLength ();
430
+ int end_pos = html.indexOf (" </li>" , start);
431
+ if (end_pos != -1 )
432
+ end_pos += 5 ;
444
433
445
434
if (end_pos != -1 && start != -1 )
446
435
{
447
436
int len = end_pos - start;
448
437
html.remove (start, len);
449
- pos -= len;
450
438
}
451
439
}
452
440
@@ -503,23 +491,24 @@ void CheckerWindow::create_html_checker(QString& checker)
503
491
// ---------------------------------------------------------------------------
504
492
void CheckerWindow::change_checker_in_template (const QString& checker, QString& html)
505
493
{
506
- QRegExp reg (" \\ {% block checker %\\ }\\ {% endblock %\\ }" );
494
+ QRegularExpression reg (" \\ {% block checker %\\ }\\ {% endblock %\\ }" , QRegularExpression::InvertedGreedinessOption );
507
495
int pos = 0 ;
508
496
509
- reg.setMinimal (true );
510
- while ((pos = reg.indexIn (html, pos)) != -1 )
511
- html.replace (pos, reg.matchedLength (), checker);
497
+ QRegularExpressionMatch match;
498
+ while ((match = reg.match (html, pos)).hasMatch ())
499
+ {
500
+ pos = match.capturedStart ();
501
+ html.replace (pos, match.capturedLength (), checker);
502
+ }
512
503
}
513
504
514
505
// ---------------------------------------------------------------------------
515
506
void CheckerWindow::change_body_script_in_template (QString& html)
516
507
{
517
- QRegExp reg (" \\ {\\ { QT_SCRIPTS \\ }\\ }" );
508
+ QRegularExpression reg (" \\ {\\ { QT_SCRIPTS \\ }\\ }" , QRegularExpression::InvertedGreedinessOption );
518
509
QString script;
519
510
int pos = 0 ;
520
511
521
- reg.setMinimal (true );
522
-
523
512
#if defined(WEB_MACHINE_KIT)
524
513
script += " <script type=\" text/javascript\" src=\" qrc:/checker/webkit.js\" ></script>\n " ;
525
514
#elif defined(WEB_MACHINE_ENGINE)
@@ -539,25 +528,26 @@ void CheckerWindow::change_body_script_in_template(QString& html)
539
528
" <script type=\" text/javascript\" src=\" qrc:/utils/text.js\" ></script>\n "
540
529
" <script type=\" text/javascript\" src=\" qrc:/menu.js\" ></script>\n " ;
541
530
542
- if ((pos = reg.indexIn (html, pos)) != -1 )
543
- html.replace (pos, reg.matchedLength (), script);
531
+ QRegularExpressionMatch match = reg.match (html, pos);
532
+ if ((pos = match.capturedStart ()) != -1 )
533
+ html.replace (pos, match.capturedLength (), script);
544
534
}
545
535
546
536
// ---------------------------------------------------------------------------
547
537
void CheckerWindow::set_webmachine_script_in_template (QString& html)
548
538
{
549
- QRegExp reg (" \\ {\\ {[\\ s]+webmachine[\\ s]\\ }\\ }" );
539
+ QRegularExpression reg (" \\ {\\ {[\\ s]+webmachine[\\ s]\\ }\\ }" , QRegularExpression::InvertedGreedinessOption );
550
540
QString machine;
551
541
int pos = 0 ;
552
542
553
- reg.setMinimal (true );
554
543
#if defined(WEB_MACHINE_KIT)
555
544
machine = " WEB_MACHINE_KIT" ;
556
545
#elif defined(WEB_MACHINE_ENGINE)
557
546
machine = " WEB_MACHINE_ENGINE" ;
558
547
#endif
559
- if ((pos = reg.indexIn (html, pos)) != -1 )
560
- html.replace (pos, reg.matchedLength (), machine);
548
+ QRegularExpressionMatch match = reg.match (html, pos);
549
+ if ((pos = match.capturedStart ()) != -1 )
550
+ html.replace (pos, match.capturedLength (), machine);
561
551
}
562
552
563
553
// ---------------------------------------------------------------------------
0 commit comments