std::string URL::fragment() const { if (hasFragment()) return _buf.substr(_parser.field_data[UF_FRAGMENT].off, _parser.field_data[UF_FRAGMENT].len); return std::string(); }
void URL::updateFragment(const std::string& fragment) { if (!hasFragment()) throw std::runtime_error("Cannot update invalid URL"); std::string tmp(str()); util::replaceInPlace(tmp, this->fragment(), fragment); parse(tmp); }
std::string URL::pathEtc() const { std::string res; res.append(path()); if (hasQuery()) { res.append("?"); res.append(query()); } if (hasFragment()) { res.append("#"); res.append(fragment()); } return res; }
ParsedURL ParsedURL::withoutFragment() const { if (!hasFragment()) return *this; ParsedURL newURL; int charactersBeforeFragemnt = m_segments.charactersBefore(URLSegments::Fragment, URLSegments::DelimiterExcluded); newURL.m_spec = URLString(m_spec.string().substringSharingImpl(0, charactersBeforeFragemnt)); newURL.m_segments = m_segments; newURL.m_segments.fragment = URLComponent(); return newURL; }