diff --git a/lib/parser/utils.cc b/lib/parser/utils.cc index f4db03a2..3f9ffa5c 100644 --- a/lib/parser/utils.cc +++ b/lib/parser/utils.cc @@ -99,37 +99,33 @@ gx_utf8_flatten (const gchar *str, gssize len) } // namespace - std::string // gx_utf8_flatten -Mux::utf8_flatten (const std::string& str) +Mux::utf8_flatten (const char *str) { - // optimization for boring old ascii strings + if (!str) + return {}; + bool is_ascii = true; - std::string s{str}; - for (auto it = s.begin(); it != s.end(); ++it) { - if (*it & 0x80) { - is_ascii = false; - break; - } else - *it = tolower(*it); + while (*str && is_ascii) { + is_ascii = *str & 0x80; + ++str; } if (G_LIKELY(is_ascii)) - return s; + return str; /////////////////////////////////////////// // seems we need the big guns - char *flat = gx_utf8_flatten (str.c_str(), str.length()); + char *flat = gx_utf8_flatten (str, -1); if (!flat) return {}; - s = flat; + std::string s{flat}; g_free (flat); return s; } - std::string Mux::utf8_clean (const std::string& dirty) { @@ -166,7 +162,6 @@ Mux::split (const std::string& str, const std::string& sepa) return vec; } - std::string Mux::quote (const std::string& str) { @@ -222,7 +217,6 @@ Mux::date_to_time_t_string (int64_t t) return buf; } - static std::string delta_ymwdhMs (const std::string& expr) { @@ -379,7 +373,6 @@ Mux::date_to_time_t_string (const std::string& dstr, bool is_first) return date_to_time_t_string (t); } - constexpr const auto SizeFormat = "%010" G_GINT64_FORMAT; constexpr const char SizeMin[] = "0000000000"; diff --git a/lib/parser/utils.hh b/lib/parser/utils.hh index 71488de8..f243cdbf 100644 --- a/lib/parser/utils.hh +++ b/lib/parser/utils.hh @@ -32,7 +32,9 @@ namespace Mux { * * @return a flattened string */ -std::string utf8_flatten (const std::string& str); +std::string utf8_flatten (const char *str); +inline std::string utf8_flatten (const std::string& s) { return utf8_flatten(s.c_str()); } + /**