utils: add from_gchars

To copy into a std::string & free.
This commit is contained in:
Dirk-Jan C. Binnema
2021-11-02 22:24:17 +02:00
parent 4e6f2a3c26
commit 388f18a278

View File

@ -130,6 +130,23 @@ std::string date_to_time_t_string(const std::string& date, bool first);
*/
std::string date_to_time_t_string(int64_t t);
/**
* Create a std::string by consuming a gchar* array; this takes ownership
* of str which should no longer be used.
*
* @param str a gchar* or NULL (latter taken as "")
*
* @return a std::string
*/
static inline std::string
from_gchars(gchar*&& str)
{
std::string s{str ? str : ""};
g_free(str);
return s;
}
using Clock = std::chrono::steady_clock;
using Duration = Clock::duration;