summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-06-14 13:09:44 +0300
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2025-06-14 13:14:03 +0300
commiteb75141d0a29d797885a18588da2d1dda9f254fc (patch)
tree13592ec5ba822dd40230b1221114d8721df2144a /lib
parent6441d26875ab254d667007cc229739c84ad9dec1 (diff)
mu_utils: add to_string_char
Like to_string_gchar, but for malloc/free strings.
Diffstat (limited to 'lib')
-rw-r--r--lib/utils/mu-utils.hh19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh
index 4e1da9c..8ec1f17 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