diff --git a/lib/message/mu-fields.cc b/lib/message/mu-fields.cc index 7f53b6a7..d6f7bc0b 100644 --- a/lib/message/mu-fields.cc +++ b/lib/message/mu-fields.cc @@ -83,14 +83,16 @@ Field::xapian_term(const std::string& s) const if (s.empty()) return res; - res.reserve(s.size() + 10); - /* slightly optimized common pure-ascii. */ - if (G_LIKELY(g_str_is_ascii(s.c_str()))) { - res += s; - for (auto i = 1U; i != res.length(); ++i) - res[i] = g_ascii_tolower(res[i]); - } else - res += utf8_flatten(s); + res.reserve(s.size() + 1); + /* optimized common pure-ascii case */ + for (auto&& c: s) { + if (G_UNLIKELY(!is_ascii(c))) { /* non-ascii after all */ + res.erase(1U); + res += utf8_flatten(s); + break; + } + res.push_back(to_ascii_lower(c)); + } if (G_UNLIKELY(res.size() > MaxTermLength)) res.erase(MaxTermLength); diff --git a/lib/message/mu-flags.hh b/lib/message/mu-flags.hh index ee01702c..6c528b6c 100644 --- a/lib/message/mu-flags.hh +++ b/lib/message/mu-flags.hh @@ -105,8 +105,7 @@ struct MessageFlagInfo { * @return lower-case shortcut */ constexpr char shortcut_lower() const { - return shortcut >= 'A' && shortcut <= 'Z' ? - shortcut + ('a' - 'A') : shortcut; + return to_ascii_lower(shortcut); } }; diff --git a/lib/message/mu-labels.cc b/lib/message/mu-labels.cc index 9b90abae..f10f1dbf 100644 --- a/lib/message/mu-labels.cc +++ b/lib/message/mu-labels.cc @@ -50,11 +50,11 @@ Mu::Labels::validate_label(const std::string &label) if (g_unichar_isalnum(uc)) continue; // alphanum is okay - if (::iscntrl(uc)) + if (is_ascii_cntrl(uc)) return Err(Error{Error::Code::InvalidArgument, "control character {} not allowed in label", static_cast(uc)}); - if (::isblank(uc)) + if (is_ascii_blank(uc)) return Err(Error{Error::Code::InvalidArgument, "blank character {} not allowed in label", static_cast(uc)}); diff --git a/lib/message/mu-message-part.cc b/lib/message/mu-message-part.cc index 3ed0b9cb..4134fb5e 100644 --- a/lib/message/mu-message-part.cc +++ b/lib/message/mu-message-part.cc @@ -49,7 +49,8 @@ cook(const std::string& fname, const std::vector& forbidden) clean.reserve(fname.length()); for (auto& c: basename(fname)) - if (seq_some(forbidden,[&](char fc){return ::iscntrl(c) || c == fc;})) + if (seq_some(forbidden,[&](char fc){ + return is_ascii_cntrl(c) || c == fc;})) clean += '-'; else clean += c; diff --git a/lib/mu-query-processor.cc b/lib/mu-query-processor.cc index ef576ad3..33d71400 100644 --- a/lib/mu-query-processor.cc +++ b/lib/mu-query-processor.cc @@ -437,7 +437,7 @@ process(const std::string& expr) /* all control chars become SPC */ std::string str{expr}; for (auto& c: str) - c = ::iscntrl(c) ? ' ' : c; + c = is_ascii_cntrl(c) ? ' ' : c; while(!str.empty()) { auto&& element = next_element(str, offset) diff --git a/lib/mu-server.cc b/lib/mu-server.cc index 35d38b31..9af1d48d 100644 --- a/lib/mu-server.cc +++ b/lib/mu-server.cc @@ -111,8 +111,9 @@ struct OutputStream { void unlink () { if (fname_.empty()) return; - if (auto&&res{::unlink(fname_.c_str())}; res != 0) - mu_warning("failed to unlink '{}'", ::strerror(res)); + if (::unlink(fname_.c_str()) != 0) + mu_warning("failed to unlink '{}': {}", fname_, + ::strerror(errno)); else mu_debug("unlinked output-stream {}", fname_); } diff --git a/lib/utils/mu-html-to-text.cc b/lib/utils/mu-html-to-text.cc index 69ff232a..ad773a4b 100644 --- a/lib/utils/mu-html-to-text.cc +++ b/lib/utils/mu-html-to-text.cc @@ -36,7 +36,7 @@ starts_with(std::string_view haystack, std::string_view needle) return false; for (auto&& c = 0U; c != needle.size(); ++c) - if (::tolower(haystack[c]) != ::tolower(needle[c])) + if (to_ascii_lower(haystack[c]) != to_ascii_lower(needle[c])) return false; return true; @@ -143,7 +143,7 @@ public: std::string_view eat_head_word() { size_t start_pos{pos_}; while (!done()) { - if (!::isalpha(html_.at(pos_))) + if (!is_ascii_alpha(html_.at(pos_))) break; ++pos_; } @@ -440,7 +440,7 @@ html_escape_char(Context& ctx) auto unescape=[escs](std::string_view esc)->char { if (esc.empty()) return ' '; - auto first{static_cast(::tolower(esc.at(0)))}; + auto first{to_ascii_lower(esc.at(0))}; auto rest=esc.substr(1); if (seq_some(escs, [&](auto&& e){return starts_with(rest, e);})) return first; diff --git a/mu/mu-cmd-cfind.cc b/mu/mu-cmd-cfind.cc index 00727909..25c75fc9 100644 --- a/mu/mu-cmd-cfind.cc +++ b/mu/mu-cmd-cfind.cc @@ -58,7 +58,7 @@ guess_nick(const Contact& contact) auto cleanup = [](const std::string& str) { std::string clean; for (auto& c: str) // XXX: support non-ascii - if (!::ispunct(c) && !::isspace(c)) + if (!is_ascii_punct(c) && !is_ascii_space(c)) clean += c; return clean; };