From eb75141d0a29d797885a18588da2d1dda9f254fc Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 14 Jun 2025 13:09:44 +0300 Subject: [PATCH] mu_utils: add to_string_char Like to_string_gchar, but for malloc/free strings. --- lib/utils/mu-utils.hh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh index 4e1da9c2..8ec1f17a 100644 --- a/lib/utils/mu-utils.hh +++ b/lib/utils/mu-utils.hh @@ -462,9 +462,9 @@ to_string_view(const std::string& s) } /** - * Consume a gchar and return a std::string + * Consume a gchar* and return a std::string * - * @param str a gchar* (consumed/freed) + * @param str a gchar* (consumed/freed with g_free()) * * @return a std::string, empty if gchar was {} */ @@ -475,7 +475,20 @@ to_string_gchar(gchar*&& str) g_free(str); return s; } - +/** + * Consume a char* and return a std::string + * + * @param str a gchar* (consumed/freed with ::free()) + * + * @return a std::string, empty if gchar was {} + */ +static inline std::string +to_string_char(char*&& str) +{ + std::string s(str?str:""); + ::free(str); + return s; +} /* * Lexnums are lexicographically sortable string representations of non-negative