diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/abaddon.cpp | 11 | ||||
-rw-r--r-- | src/discord/snowflake.cpp | 11 | ||||
-rw-r--r-- | src/discord/snowflake.hpp | 2 | ||||
-rw-r--r-- | src/platform.cpp | 4 | ||||
-rw-r--r-- | src/util.cpp | 9 |
5 files changed, 23 insertions, 14 deletions
diff --git a/src/abaddon.cpp b/src/abaddon.cpp index f6c9ef5..db8c02a 100644 --- a/src/abaddon.cpp +++ b/src/abaddon.cpp @@ -723,6 +723,17 @@ EmojiResource &Abaddon::GetEmojis() { int main(int argc, char **argv) { if (std::getenv("ABADDON_NO_FC") == nullptr) Platform::SetupFonts(); + + char *systemLocale = std::setlocale(LC_ALL, ""); + try { + std::locale::global(std::locale(systemLocale)); + } catch (...) { + try { + std::locale::global(std::locale::classic()); + std::setlocale(LC_ALL, systemLocale); + } catch (...) {} + } + #if defined(_WIN32) && defined(_MSC_VER) TCHAR buf[2] { 0 }; GetEnvironmentVariableA("GTK_CSD", buf, sizeof(buf)); diff --git a/src/discord/snowflake.cpp b/src/discord/snowflake.cpp index cea9153..6909a15 100644 --- a/src/discord/snowflake.cpp +++ b/src/discord/snowflake.cpp @@ -2,6 +2,7 @@ #include <ctime> #include <iomanip> #include <chrono> +#include <glibmm.h> constexpr static uint64_t DiscordEpochSeconds = 1420070400; @@ -42,14 +43,12 @@ bool Snowflake::IsValid() const { return m_num != Invalid; } -std::string Snowflake::GetLocalTimestamp() const { +Glib::ustring Snowflake::GetLocalTimestamp() const { const time_t secs_since_epoch = (m_num / SecondsInterval) + DiscordEpochSeconds; const std::tm tm = *localtime(&secs_since_epoch); - std::stringstream ss; - const static std::locale locale(""); - ss.imbue(locale); - ss << std::put_time(&tm, "%X %x"); - return ss.str(); + std::array<char, 256> tmp; + std::strftime(tmp.data(), sizeof(tmp), "%X %x", &tm); + return tmp.data(); } void from_json(const nlohmann::json &j, Snowflake &s) { diff --git a/src/discord/snowflake.hpp b/src/discord/snowflake.hpp index 0b79723..1cabf3d 100644 --- a/src/discord/snowflake.hpp +++ b/src/discord/snowflake.hpp @@ -12,7 +12,7 @@ struct Snowflake { static Snowflake FromNow(); // not thread safe bool IsValid() const; - std::string GetLocalTimestamp() const; + Glib::ustring GetLocalTimestamp() const; bool operator==(const Snowflake &s) const noexcept { return m_num == s.m_num; diff --git a/src/platform.cpp b/src/platform.cpp index ce744d7..dfbea3b 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -7,10 +7,10 @@ using namespace std::literals::string_literals; -#if defined(_WIN32) && defined(_MSC_VER) +#if defined(_WIN32) #include <Windows.h> #include <Shlwapi.h> - #include <ShlObj_core.h> + #include <ShlObj.h> #include <pango/pangocairo.h> #include <pango/pangofc-fontmap.h> #pragma comment(lib, "Shlwapi.lib") diff --git a/src/util.cpp b/src/util.cpp index 34ca6d4..1a7182d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,5 +1,6 @@ #include "util.hpp" #include <filesystem> +#include <array> Semaphore::Semaphore(int count) : m_count(count) {} @@ -93,11 +94,9 @@ std::string FormatISO8601(const std::string &in, int extra_offset, const std::st int offset = GetTimezoneOffset(); tm.tm_sec += offset + extra_offset; mktime(&tm); - std::stringstream ss; - const static std::locale locale(""); - ss.imbue(locale); - ss << std::put_time(&tm, fmt.c_str()); - return ss.str(); + std::array<char, 512> tmp; + std::strftime(tmp.data(), sizeof(tmp), fmt.c_str(), &tm); + return tmp.data(); } void ScrollListBoxToSelected(Gtk::ListBox &list) { |