| 1617 | } |
| 1618 | |
| 1619 | DocumentObject* DocumentObject::resolveRelativeLink(std::string& subname, |
| 1620 | DocumentObject*& link, |
| 1621 | std::string& linkSub) const |
| 1622 | { |
| 1623 | if (!link || !link->isAttachedToDocument() || !isAttachedToDocument()) { |
| 1624 | return nullptr; |
| 1625 | } |
| 1626 | auto ret = const_cast<DocumentObject*>(this); |
| 1627 | if (link != ret) { |
| 1628 | auto sub = subname.c_str(); |
| 1629 | auto nextsub = sub; |
| 1630 | for (auto dot = strchr(nextsub, '.'); dot; nextsub = dot + 1, dot = strchr(nextsub, '.')) { |
| 1631 | std::string subcheck(sub, nextsub - sub); |
| 1632 | subcheck += link->getNameInDocument(); |
| 1633 | subcheck += '.'; |
| 1634 | if (getSubObject(subcheck.c_str()) == link) { |
| 1635 | ret = getSubObject(std::string(sub, dot + 1 - sub).c_str()); |
| 1636 | if (!ret) { |
| 1637 | return nullptr; |
| 1638 | } |
| 1639 | subname = std::string(dot + 1); |
| 1640 | break; |
| 1641 | } |
| 1642 | } |
| 1643 | return ret; |
| 1644 | } |
| 1645 | |
| 1646 | size_t pos = 0, linkPos = 0; |
| 1647 | std::string linkssub, ssub; |
| 1648 | do { |
| 1649 | linkPos = linkSub.find('.', linkPos); |
| 1650 | if (linkPos == std::string::npos) { |
| 1651 | link = nullptr; |
| 1652 | return nullptr; |
| 1653 | } |
| 1654 | ++linkPos; |
| 1655 | pos = subname.find('.', pos); |
| 1656 | if (pos == std::string::npos) { |
| 1657 | subname.clear(); |
| 1658 | ret = nullptr; |
| 1659 | break; |
| 1660 | } |
| 1661 | ++pos; |
| 1662 | } while (subname.compare(0, pos, linkSub, 0, linkPos) == 0); |
| 1663 | |
| 1664 | if (pos != std::string::npos) { |
| 1665 | ret = getSubObject(subname.substr(0, pos).c_str()); |
| 1666 | if (!ret) { |
| 1667 | link = nullptr; |
| 1668 | return nullptr; |
| 1669 | } |
| 1670 | subname = subname.substr(pos); |
| 1671 | } |
| 1672 | if (linkPos) { |
| 1673 | link = link->getSubObject(linkSub.substr(0, linkPos).c_str()); |
| 1674 | if (!link) { |
| 1675 | return nullptr; |
| 1676 | } |
no test coverage detected