supercell-wx/scwx-qt/source/scwx/qt/util/network.cpp
AdenKoperczak b13d2106d4 Fixed issue with NormalizeUrl where whitespace trimming was not
happening on non-local files, and added test cases.
2024-11-25 11:42:17 -05:00

37 lines
682 B
C++

#include <scwx/qt/util/network.hpp>
#include <QDir>
#include <QUrl>
namespace scwx
{
namespace qt
{
namespace util
{
namespace network
{
std::string NormalizeUrl(const std::string& urlString)
{
std::string normalizedUrl;
// Normalize URL string
QString trimmedUrlString = QString::fromStdString(urlString).trimmed();
QUrl url = QUrl::fromUserInput(trimmedUrlString);
if (url.isLocalFile())
{
normalizedUrl = QDir::toNativeSeparators(url.toLocalFile()).toStdString();
}
else
{
normalizedUrl = trimmedUrlString.toStdString();
}
return normalizedUrl;
}
} // namespace network
} // namespace util
} // namespace qt
} // namespace scwx