summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2022-12-10 19:22:00 +0200
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2022-12-12 10:41:07 +0200
commit0fd90207268ee37fbf1bbbc3a7851b287712fd29 (patch)
treea4871aee48cb1f6d16ee8ce1b1201cfac66e5251
parent3b1d1edd463030fb293ccae45693db42932bf8d9 (diff)
mu-utils: use const char* from for time_to_string
To avoid lifetime problems with some(?) compilers.
-rw-r--r--lib/utils/mu-utils.cc12
-rw-r--r--lib/utils/mu-utils.hh2
2 files changed, 6 insertions, 8 deletions
diff --git a/lib/utils/mu-utils.cc b/lib/utils/mu-utils.cc
index f32eed7..6a88788 100644
--- a/lib/utils/mu-utils.cc
+++ b/lib/utils/mu-utils.cc
@@ -346,12 +346,9 @@ Mu::vformat(const char* frm, va_list args)
}
std::string
-Mu::time_to_string(const std::string& frm_, time_t t, bool utc)
+Mu::time_to_string(const char *frm, time_t t, bool utc)
{
- /* Temporary hack... https://github.com/djcb/mu/issues/2230 */
- const auto frm =
- g_utf8_validate(frm_.c_str(), frm_.length(), {}) ?
- frm_ : "%c";
+ g_return_val_if_fail(frm, "");
GDateTime* dt = std::invoke([&] {
if (utc)
@@ -366,10 +363,11 @@ Mu::time_to_string(const std::string& frm_, time_t t, bool utc)
return {};
}
- auto datestr{to_string_opt_gchar(g_date_time_format(dt, frm.c_str()))};
+ frm = frm ? frm : "%c";
+ auto datestr{to_string_opt_gchar(g_date_time_format(dt, frm))};
g_date_time_unref(dt);
if (!datestr)
- g_warning("failed to format time with format '%s'", frm.c_str());
+ g_warning("failed to format time with format '%s'", frm);
return datestr.value_or("");
}
diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh
index dd38416..4a9f70d 100644
--- a/lib/utils/mu-utils.hh
+++ b/lib/utils/mu-utils.hh
@@ -153,7 +153,7 @@ std::string date_to_time_t_string(int64_t t);
* @return a string representation of the time in UTF8-format, or empty in case
* of error.
*/
-std::string time_to_string(const std::string& frm, time_t t, bool utc = false) G_GNUC_CONST;
+std::string time_to_string(const char *frm, time_t t, bool utc = false) G_GNUC_CONST;
/**