1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-18 00:42:13 +03:00

Use C++ locale based functions instead of the libc ones

This commit is contained in:
Maxime Coste 2016-05-11 09:49:45 +01:00
parent 6b1bd84e8e
commit 84f62e6ff2
3 changed files with 10 additions and 6 deletions

View File

@ -884,7 +884,7 @@ void expand_unprintable(const Context& context, HighlightFlags flags, DisplayBuf
{
auto coord = it.coord();
Codepoint cp = utf8::read_codepoint<utf8::InvalidPolicy::Pass>(it, end);
if (cp != '\n' and not iswprint(cp))
if (cp != '\n' and not std::isprint((wchar_t)cp, std::locale{}))
{
if (coord != atom_it->begin())
atom_it = ++line.split(atom_it, coord);

View File

@ -34,6 +34,7 @@ using Utf8It = utf8::iterator<const char*>;
static int count_word_boundaries_match(StringView candidate, StringView query)
{
std::locale locale;
int count = 0;
Utf8It query_it{query.begin(), query};
Codepoint prev = 0;
@ -41,8 +42,10 @@ static int count_word_boundaries_match(StringView candidate, StringView query)
{
const Codepoint c = *it;
const bool is_word_boundary = prev == 0 or
(!iswalnum(prev) and iswalnum(c)) or
(islower(prev) and isupper(c));
(!std::isalnum((wchar_t)prev, locale) and
std::isalnum((wchar_t)c, locale)) or
(std::islower((wchar_t)prev, locale) and
std::isupper((wchar_t)c, locale));
prev = c;
if (not is_word_boundary)

View File

@ -2,6 +2,7 @@
#define unicode_hh_INCLUDED
#include <wctype.h>
#include <locale>
namespace Kakoune
{
@ -28,7 +29,7 @@ enum WordType { Word, WORD };
template<WordType word_type = Word>
inline bool is_word(Codepoint c)
{
return c == '_' or iswalnum(c);
return c == '_' or std::isalnum((wchar_t)c, std::locale{});
}
template<>
@ -67,8 +68,8 @@ inline CharCategories categorize(Codepoint c)
return CharCategories::Punctuation;
}
inline Codepoint to_lower(Codepoint cp) { return towlower((wchar_t)cp); }
inline Codepoint to_upper(Codepoint cp) { return towupper((wchar_t)cp); }
inline Codepoint to_lower(Codepoint cp) { return std::tolower((wchar_t)cp, std::locale{}); }
inline Codepoint to_upper(Codepoint cp) { return std::toupper((wchar_t)cp, std::locale{}); }
inline char to_lower(char c) { return c >= 'A' and c <= 'Z' ? c - 'A' + 'a' : c; }
inline char to_upper(char c) { return c >= 'a' and c <= 'z' ? c - 'a' + 'A' : c; }