From 6ce94ce9142c86c7f62bc906e8def55148d0f439 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 19 Sep 2023 23:43:15 +0300 Subject: [PATCH] mu-utils: add to_string_view --- lib/utils/mu-utils.hh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh index 115d0ae2..fcc450d0 100644 --- a/lib/utils/mu-utils.hh +++ b/lib/utils/mu-utils.hh @@ -425,6 +425,19 @@ to_string(const T& val) return sstr.str(); } +/** + * Convert to std::string to a std::string_view + * Careful with the lifetimes! + * + * @param s a string + * + * @return a string_view + */ +static inline std::string_view +to_string_view(const std::string& s) +{ + return std::string_view{s.data(), s.size()}; +} /** * Consume a gchar and return a std::string