lib: use ascii ctype utils
Use the new ascii ctype utils.
This commit is contained in:
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -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<int>(uc)});
|
||||
if (::isblank(uc))
|
||||
if (is_ascii_blank(uc))
|
||||
return Err(Error{Error::Code::InvalidArgument,
|
||||
"blank character {} not allowed in label",
|
||||
static_cast<int>(uc)});
|
||||
|
||||
@ -49,7 +49,8 @@ cook(const std::string& fname, const std::vector<char>& 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;
|
||||
|
||||
Reference in New Issue
Block a user