| 563 | } |
| 564 | |
| 565 | void RichResourceTextInitialise(QVariant &var, ICaptureContext *ctx, bool parseURLs) |
| 566 | { |
| 567 | // we only upconvert from strings, any other type with a string representation is not expected to |
| 568 | // contain ResourceIds. In particular if the variant is already a ResourceId we can return. |
| 569 | if(GetVariantMetatype(var) != QMetaType::QString) |
| 570 | return; |
| 571 | |
| 572 | // we trim the string because that will happen naturally when rendering as HTML, and it makes it |
| 573 | // easier to detect strings where the only contents are ResourceId text. |
| 574 | QString text = var.toString().trimmed(); |
| 575 | |
| 576 | // do a simple string search first before using regular expressions |
| 577 | if(!text.contains(lit("ResourceId::")) && !text.contains(lit("GPUAddress::")) && |
| 578 | !text.contains(lit("__rd_msgs::")) && !text.contains(QLatin1Char('@')) && !parseURLs && |
| 579 | !(text.startsWith(lit("<rdhtml>")) && text.endsWith(lit("</rdhtml>")))) |
| 580 | return; |
| 581 | |
| 582 | // two forms: GPUAddress::012345 - typeless |
| 583 | // GPUAddress::012345::991 - using type 991 from PointerTypeRegistry |
| 584 | static QRegularExpression addrRE(lit("GPUAddress::([0-9]*)(::([0-9]*))?")); |
| 585 | |
| 586 | QRegularExpressionMatch match = addrRE.match(text); |
| 587 | |
| 588 | if(match.hasMatch()) |
| 589 | { |
| 590 | // don't support mixed text & addresses. Only do the replacement if we matched the whole string |
| 591 | if(match.capturedStart(0) == 0 && match.capturedLength(0) == text.length()) |
| 592 | { |
| 593 | GPUAddressPtr addr(new GPUAddress); |
| 594 | addr->val.pointer = match.captured(1).toULongLong(); |
| 595 | |
| 596 | // we deliberately set this to ResourceId() to indicate that we're using an ID from the |
| 597 | // registry, not a shader-relative index |
| 598 | addr->val.shader = ResourceId(); |
| 599 | addr->val.pointerTypeID = match.captured(3).toULong(); |
| 600 | |
| 601 | var = QVariant::fromValue(addr); |
| 602 | return; |
| 603 | } |
| 604 | |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | const bool forcehtml = text.startsWith(lit("<rdhtml>")) && text.endsWith(lit("</rdhtml>")); |
| 609 | if(forcehtml) |
| 610 | { |
| 611 | text = text.mid(8, text.length() - 17); |
| 612 | } |
| 613 | |
| 614 | // use regexp to split up into fragments of text and resourceid. The resourceid is then |
| 615 | // formatted on the fly in RichResourceText::cacheDocument |
| 616 | static QRegularExpression resRE( |
| 617 | lit("(ResourceId::)([0-9]+)|(@)([0-9]+)|(__rd_msgs::)([0-9]+):([0-9]+)")); |
| 618 | |
| 619 | match = resRE.match(text); |
| 620 | |
| 621 | RichResourceTextPtr linkedText(new RichResourceText); |
| 622 |
no test coverage detected