Mercurial > minori
diff src/core/strings.cc @ 202:71832ffe425a
animia: re-add kvm fd source
this is all being merged from my wildly out-of-date laptop. SORRY!
in other news, I edited the CI file to install the wayland client
as well, so the linux CI build might finally get wayland stuff.
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Tue, 02 Jan 2024 06:05:06 -0500 |
| parents | 9613d72b097e |
| children | 7cf53145de11 |
line wrap: on
line diff
--- a/src/core/strings.cc Sun Nov 19 19:13:28 2023 -0500 +++ b/src/core/strings.cc Tue Jan 02 06:05:06 2024 -0500 @@ -2,10 +2,13 @@ * strings.cpp: Useful functions for manipulating strings **/ #include "core/strings.h" +#include "core/session.h" // locale + #include <QByteArray> #include <QDebug> #include <QString> #include <QLocale> + #include <algorithm> #include <cctype> #include <codecvt> @@ -20,12 +23,15 @@ std::string Implode(const std::vector<std::string>& vector, const std::string& delimiter) { if (vector.size() < 1) return "-"; + std::string out = ""; + for (unsigned long long i = 0; i < vector.size(); i++) { out.append(vector.at(i)); if (i < vector.size() - 1) out.append(delimiter); } + return out; } @@ -113,20 +119,15 @@ /* let Qt handle the heavy lifting of locale shit I don't want to deal with */ std::string ToUpper(const std::string& string) { - /* todo: this "locale" will have to be moved to session.h - it also defaults to en-US, which sucks very much for - anyone who doesn't speak american english... */ - QLocale locale; - return ToUtf8String(locale.toUpper(ToQString(string))); + return ToUtf8String(session.config.locale.GetLocale().toUpper(ToQString(string))); } std::string ToLower(const std::string& string) { - QLocale locale; - return ToUtf8String(locale.toLower(ToQString(string))); + return ToUtf8String(session.config.locale.GetLocale().toLower(ToQString(string))); } std::wstring ToWstring(const std::string& string) { - std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; + static std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; return converter.from_bytes(string); } @@ -137,12 +138,12 @@ } std::string ToUtf8String(const std::wstring& wstring) { - std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; + static std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter; return converter.to_bytes(wstring); } std::string ToUtf8String(const QString& string) { - QByteArray ba = string.toUtf8(); + const QByteArray ba = string.toUtf8(); return std::string(ba.constData(), ba.size()); } @@ -173,7 +174,7 @@ bool ToBool(const std::string& s, const bool def) { if (s.length() < 4) return def; - std::string l = Strings::ToLower(s); + const std::string l = Strings::ToLower(s); if (Strings::BeginningMatchesSubstring(l, "true")) return true; else if (Strings::BeginningMatchesSubstring(l, "false")) @@ -186,7 +187,7 @@ } uint64_t HumanReadableSizeToBytes(const std::string& str) { - const std::unordered_map<std::string, uint64_t> bytes_map = { + static const std::unordered_map<std::string, uint64_t> bytes_map = { {"KB", 1ull << 10}, {"MB", 1ull << 20}, {"GB", 1ull << 30}, @@ -222,6 +223,7 @@ for (unsigned long long i = 0; i < str.length() && i < sub.length(); i++) if (str[i] != sub[i]) return false; + return true; }
