| 526 | } |
| 527 | |
| 528 | bool HandleURLFragment(RichResourceTextPtr linkedText, QString text, bool parseURLs) |
| 529 | { |
| 530 | bool hasURL = false; |
| 531 | if(parseURLs) |
| 532 | { |
| 533 | static QRegularExpression urlRE(lit( |
| 534 | R"(https?://([a-zA-Z0-9]+\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}.([a-z]{2,8})+/[-a-zA-Z0-9@:%_+.~#?&/=]*)")); |
| 535 | |
| 536 | QRegularExpressionMatch urlMatch = urlRE.match(text); |
| 537 | |
| 538 | while(urlMatch.hasMatch()) |
| 539 | { |
| 540 | QUrl url = urlMatch.captured(0); |
| 541 | |
| 542 | int end = urlMatch.capturedEnd(); |
| 543 | |
| 544 | // push any text that preceeded the url. |
| 545 | if(urlMatch.capturedStart(0) > 0) |
| 546 | linkedText->fragments.push_back(text.left(urlMatch.capturedStart(0))); |
| 547 | |
| 548 | text.remove(0, end); |
| 549 | |
| 550 | linkedText->fragments.push_back(url); |
| 551 | |
| 552 | urlMatch = urlRE.match(text); |
| 553 | |
| 554 | hasURL = true; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | if(!text.isEmpty()) |
| 559 | { |
| 560 | linkedText->fragments.push_back(text); |
| 561 | } |
| 562 | return hasURL; |
| 563 | } |
| 564 | |
| 565 | void RichResourceTextInitialise(QVariant &var, ICaptureContext *ctx, bool parseURLs) |
| 566 | { |