2022-11-03 19:41:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QString>
|
2023-05-07 03:10:58 +01:00
|
|
|
#include <QUrl>
|
2022-11-03 19:41:55 +00:00
|
|
|
|
|
|
|
namespace StringUtils {
|
2022-11-03 19:44:23 +00:00
|
|
|
|
|
|
|
#if defined Q_OS_WIN32
|
2022-11-03 19:59:03 +00:00
|
|
|
using string = std::wstring;
|
|
|
|
|
|
|
|
inline string toStdString(QString s)
|
2022-11-03 19:44:23 +00:00
|
|
|
{
|
|
|
|
return s.toStdWString();
|
|
|
|
}
|
2022-11-03 19:59:03 +00:00
|
|
|
inline QString fromStdString(string s)
|
|
|
|
{
|
|
|
|
return QString::fromStdWString(s);
|
|
|
|
}
|
2022-11-03 19:44:23 +00:00
|
|
|
#else
|
2022-11-03 19:59:03 +00:00
|
|
|
using string = std::string;
|
|
|
|
|
|
|
|
inline string toStdString(QString s)
|
2022-11-03 19:44:23 +00:00
|
|
|
{
|
|
|
|
return s.toStdString();
|
|
|
|
}
|
2022-11-03 19:59:03 +00:00
|
|
|
inline QString fromStdString(string s)
|
|
|
|
{
|
|
|
|
return QString::fromStdString(s);
|
|
|
|
}
|
2022-11-03 19:44:23 +00:00
|
|
|
#endif
|
|
|
|
|
2022-11-03 19:41:55 +00:00
|
|
|
int naturalCompare(const QString& s1, const QString& s2, Qt::CaseSensitivity cs);
|
2023-05-07 03:10:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Truncate a url while keeping its readability py placing the `...` in the middle of the path
|
|
|
|
* @param url Url to truncate
|
|
|
|
* @param max_len max lenght of url in charaters
|
|
|
|
* @param hard_limit if truncating the path can't get the url short enough, truncate it normaly.
|
|
|
|
*/
|
|
|
|
QString truncateUrlHumanFriendly(QUrl &url, int max_len, bool hard_limit = false);
|
|
|
|
|
|
|
|
QString humanReadableFileSize(double bytes, bool use_si = false, int decimal_points = 1);
|
|
|
|
|
2022-11-03 19:41:55 +00:00
|
|
|
} // namespace StringUtils
|