return ret;
}
-
-// true of a comparison from the end of parent terminates
+// are WE part of parent
bool DNSName::isPartOf(const DNSName& parent) const
{
- auto us = d_storage.crbegin();
- auto p = parent.d_storage.crbegin();
- for(; us != d_storage.crend() && p != parent.d_storage.crend(); ++us, ++p) {
- if(tolower(*p) != tolower(*us))
- break;
+ if(parent.d_storage.size() > d_storage.size())
+ return false;
+
+ // this is slightly complicated since we can't start from the end, since we can't see where a label begins/ends then
+ for(auto us=d_storage.cbegin(); us<d_storage.cend() && d_storage.cend()-us >= (unsigned int)parent.d_storage.size(); us+=*us+1) {
+ if (d_storage.cend()-us == (unsigned int)parent.d_storage.size()) {
+ auto p = parent.d_storage.cbegin();
+ for(; us != d_storage.cend() && p != parent.d_storage.cend(); ++us, ++p) {
+ if(tolower(*p) != tolower(*us))
+ break;
+ }
+ return (p==parent.d_storage.end());
+ }
}
- return (p==parent.d_storage.crend());
+ return false;
}
void DNSName::appendRawLabel(const std::string& label)
BOOST_CHECK_EQUAL(before, after);
DNSName wwwds9anl("www.ds9a.nl.");
+ DNSName wwwds9anl1("www.ds9a\002nl.");
DNSName nl("nl.");
BOOST_CHECK(wwwds9anl.isPartOf(nl));
+ BOOST_CHECK(!wwwds9anl1.isPartOf(nl));
BOOST_CHECK(wwwds9anl.isPartOf(wwwds9anl));
BOOST_CHECK(!nl.isPartOf(wwwds9anl));