mu-utils: try g_autoptr/g_autofree

It's useful, but let's if it works for all targets.
This commit is contained in:
Dirk-Jan C. Binnema 2022-02-06 12:28:18 +02:00
parent d0a3ca3453
commit 8493e8649d
1 changed files with 2 additions and 4 deletions

View File

@ -131,8 +131,8 @@ Mu::utf8_flatten(const char* str)
std::string
Mu::utf8_clean(const std::string& dirty)
{
GString* gstr = g_string_sized_new(dirty.length());
auto cstr = mu_str_utf8ify(dirty.c_str());
g_autoptr(GString) gstr = g_string_sized_new(dirty.length());
g_autofree char *cstr = mu_str_utf8ify(dirty.c_str());
for (auto cur = cstr; cur && *cur; cur = g_utf8_next_char(cur)) {
const gunichar uc = g_utf8_get_char(cur);
@ -142,9 +142,7 @@ Mu::utf8_clean(const std::string& dirty)
g_string_append_unichar(gstr, uc);
}
g_free(cstr);
std::string clean(gstr->str, gstr->len);
g_string_free(gstr, TRUE);
clean.erase(0, clean.find_first_not_of(" "));
clean.erase(clean.find_last_not_of(" ") + 1); // remove trailing space