mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 10:25:36 +08:00
feat: Support URL fragments with CUrl
URL fragments are the part of a URL to select subresources by using "#"
This commit is contained in:
@@ -102,6 +102,16 @@ namespace BlackMisc::Network
|
||||
this->appendQuery(key + "=" + value);
|
||||
}
|
||||
|
||||
bool CUrl::hasFragment() const
|
||||
{
|
||||
return !m_fragment.isEmpty();
|
||||
}
|
||||
|
||||
void CUrl::setFragment(const QString &fragment)
|
||||
{
|
||||
m_fragment = fragment;
|
||||
}
|
||||
|
||||
QString CUrl::getFullUrl(bool withQuery) const
|
||||
{
|
||||
if (m_host.isEmpty()) { return {}; }
|
||||
@@ -109,6 +119,7 @@ namespace BlackMisc::Network
|
||||
QString qn(m_host);
|
||||
if (!hasDefaultPort() && hasPort()) { qn = qn.append(":").append(QString::number(m_port)); }
|
||||
if (hasPath()) { qn = qn.append("/").append(m_path).replace("//", "/"); }
|
||||
if (hasFragment()) { qn = qn.append("#").append(m_fragment).replace("//", "/"); }
|
||||
if (hasQuery() && withQuery) { qn = qn.append("?").append(m_query); }
|
||||
if (hasScheme()) { qn = QString(this->getScheme()).append("://").append(qn); }
|
||||
return qn;
|
||||
@@ -136,6 +147,7 @@ namespace BlackMisc::Network
|
||||
this->setScheme(url.scheme());
|
||||
this->setPath(url.path());
|
||||
this->setQuery(url.query());
|
||||
this->setFragment(url.fragment());
|
||||
}
|
||||
|
||||
QNetworkRequest CUrl::toNetworkRequest() const
|
||||
|
||||
@@ -22,7 +22,7 @@ BLACK_DECLARE_VALUEOBJECT_MIXINS(BlackMisc::Network, CUrl)
|
||||
namespace BlackMisc::Network
|
||||
{
|
||||
//! Value object encapsulating information of a location,
|
||||
//! kind of simplied CValueObject compliant version of QUrl
|
||||
//! kind of simplified CValueObject compliant version of QUrl
|
||||
class BLACKMISC_EXPORT CUrl : public CValueObject<CUrl>
|
||||
{
|
||||
public:
|
||||
@@ -105,6 +105,12 @@ namespace BlackMisc::Network
|
||||
//! Append query
|
||||
void appendQuery(const QString &key, const QString &value);
|
||||
|
||||
//! Fragment string?
|
||||
bool hasFragment() const;
|
||||
|
||||
//! Set fragment
|
||||
void setFragment(const QString &fragment);
|
||||
|
||||
//! Empty
|
||||
bool isEmpty() const;
|
||||
|
||||
@@ -194,6 +200,7 @@ namespace BlackMisc::Network
|
||||
int m_port = -1;
|
||||
QString m_path;
|
||||
QString m_query;
|
||||
QString m_fragment;
|
||||
|
||||
static QString stripQueryString(const QString &query);
|
||||
|
||||
@@ -203,7 +210,8 @@ namespace BlackMisc::Network
|
||||
BLACK_METAMEMBER(host),
|
||||
BLACK_METAMEMBER(port),
|
||||
BLACK_METAMEMBER(path),
|
||||
BLACK_METAMEMBER(query)
|
||||
BLACK_METAMEMBER(query),
|
||||
BLACK_METAMEMBER(fragment)
|
||||
);
|
||||
};
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user