mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
Ref T150, utility functions in URL list
* renamed to withAppendedPath * findByHost * addFailed utility functions
This commit is contained in:
committed by
Mathew Sutcliffe
parent
fe01a9d4aa
commit
afbf3f05c8
@@ -8,8 +8,9 @@
|
||||
*/
|
||||
|
||||
#include "blackmisc/network/urllist.h"
|
||||
#include "blackmisc/math/mathutils.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
#include "blackmisc/math/mathutils.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <tuple>
|
||||
@@ -68,7 +69,7 @@ namespace BlackMisc
|
||||
return copy.getRandomUrl();
|
||||
}
|
||||
|
||||
CUrlList CUrlList::appendPath(const QString &path) const
|
||||
CUrlList CUrlList::withAppendedPath(const QString &path) const
|
||||
{
|
||||
if (path.isEmpty() || this->isEmpty()) { return (*this); }
|
||||
CUrlList urls;
|
||||
@@ -79,6 +80,20 @@ namespace BlackMisc
|
||||
return urls;
|
||||
}
|
||||
|
||||
CUrlList CUrlList::findByHost(const QString &host, Qt::CaseSensitivity cs) const
|
||||
{
|
||||
CUrlList result;
|
||||
if (host.isEmpty() || this->isEmpty()) { return result; }
|
||||
for (const CUrl &url : *this)
|
||||
{
|
||||
if (stringCompare(url.getHost(), host, cs))
|
||||
{
|
||||
result.push_back(url);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString CUrlList::convertToQString(const QString &separator, bool i18n) const
|
||||
{
|
||||
const QStringList sl(toStringList(i18n));
|
||||
@@ -136,6 +151,26 @@ namespace BlackMisc
|
||||
return hasMoreUrlsToTry();
|
||||
}
|
||||
|
||||
bool CFailoverUrlList::addFailedUrls(const CUrlList &failedUrls)
|
||||
{
|
||||
this->m_failedUrls.push_back(failedUrls);
|
||||
return hasMoreUrlsToTry();
|
||||
}
|
||||
|
||||
bool CFailoverUrlList::addFailedHost(const CUrl &failedUrl)
|
||||
{
|
||||
Q_ASSERT_X(!failedUrl.isEmpty(), Q_FUNC_INFO, "empty URL as failed");
|
||||
const QString host = failedUrl.getHost();
|
||||
return CFailoverUrlList::addFailedHost(host);
|
||||
}
|
||||
|
||||
bool CFailoverUrlList::addFailedHost(const QString &host, Qt::CaseSensitivity cs)
|
||||
{
|
||||
if (host.isEmpty()) { return this->hasMoreUrlsToTry(); }
|
||||
const CUrlList failedUrls = this->findByHost(host, cs);
|
||||
return addFailedUrls(failedUrls);
|
||||
}
|
||||
|
||||
bool CFailoverUrlList::hasMoreUrlsToTry() const
|
||||
{
|
||||
if (this->isEmpty()) { return false; }
|
||||
|
||||
Reference in New Issue
Block a user