mirror of
https://github.com/mawww/kakoune.git
synced 2025-01-02 00:32:07 +03:00
Go back to libc locale and use c_regex_traits
Unfortunately, cygwin does not support c++ locales.
This commit is contained in:
parent
e1703204f8
commit
1834a67b87
@ -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 std::isprint((wchar_t)cp, std::locale{}))
|
||||
if (cp != '\n' and not iswprint((wchar_t)cp))
|
||||
{
|
||||
if (coord != atom_it->begin())
|
||||
atom_it = ++line.split(atom_it, coord);
|
||||
|
@ -707,8 +707,7 @@ int run_pipe(StringView session)
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try { std::locale::global(std::locale("")); }
|
||||
catch (std::runtime_error&) { setlocale(LC_ALL, ""); }
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
set_signal_handler(SIGSEGV, signal_handler);
|
||||
set_signal_handler(SIGFPE, signal_handler);
|
||||
|
@ -34,7 +34,6 @@ 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;
|
||||
@ -42,10 +41,8 @@ static int count_word_boundaries_match(StringView candidate, StringView query)
|
||||
{
|
||||
const Codepoint c = *it;
|
||||
const bool is_word_boundary = prev == 0 or
|
||||
(!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));
|
||||
(!iswalnum((wchar_t)prev) and iswalnum((wchar_t)c)) or
|
||||
(iswlower((wchar_t)prev) and iswupper((wchar_t)c));
|
||||
prev = c;
|
||||
|
||||
if (not is_word_boundary)
|
||||
|
@ -8,7 +8,7 @@ namespace Kakoune
|
||||
using Utf8It = RegexUtf8It<const char*>;
|
||||
|
||||
Regex::Regex(StringView re, flag_type flags) try
|
||||
: boost::wregex{Utf8It{re.begin(), re}, Utf8It{re.end(), re}}, m_str(re.str())
|
||||
: RegexBase{Utf8It{re.begin(), re}, Utf8It{re.end(), re}}, m_str(re.str())
|
||||
{} catch (std::runtime_error& err) { throw regex_error(err.what()); }
|
||||
|
||||
String option_to_string(const Regex& re)
|
||||
|
17
src/regex.hh
17
src/regex.hh
@ -17,8 +17,10 @@ struct regex_error : runtime_error
|
||||
{}
|
||||
};
|
||||
|
||||
using RegexBase = boost::basic_regex<wchar_t, boost::c_regex_traits<wchar_t>>;
|
||||
|
||||
// Regex that keeps track of its string representation
|
||||
struct Regex : boost::wregex
|
||||
struct Regex : RegexBase
|
||||
{
|
||||
Regex() = default;
|
||||
|
||||
@ -36,6 +38,10 @@ private:
|
||||
template<typename It>
|
||||
using RegexUtf8It = utf8::iterator<It, wchar_t, ssize_t>;
|
||||
|
||||
template<typename It>
|
||||
using RegexIteratorBase = boost::regex_iterator<RegexUtf8It<It>, wchar_t,
|
||||
boost::c_regex_traits<wchar_t>>;
|
||||
|
||||
namespace RegexConstant = boost::regex_constants;
|
||||
|
||||
template<typename Iterator>
|
||||
@ -70,19 +76,18 @@ struct MatchResults : boost::match_results<RegexUtf8It<Iterator>>
|
||||
};
|
||||
|
||||
template<typename Iterator>
|
||||
struct RegexIterator : boost::regex_iterator<RegexUtf8It<Iterator>>
|
||||
struct RegexIterator : RegexIteratorBase<Iterator>
|
||||
{
|
||||
using ParentType = boost::regex_iterator<RegexUtf8It<Iterator>>;
|
||||
using Utf8It = RegexUtf8It<Iterator>;
|
||||
using ValueType = MatchResults<Iterator>;
|
||||
|
||||
RegexIterator() = default;
|
||||
RegexIterator(Iterator begin, Iterator end, const Regex& re,
|
||||
RegexConstant::match_flag_type flags = RegexConstant::match_default)
|
||||
: ParentType{Utf8It{begin, begin, end}, Utf8It{end, begin, end}, re, flags} {}
|
||||
: RegexIteratorBase<Iterator>{Utf8It{begin, begin, end}, Utf8It{end, begin, end}, re, flags} {}
|
||||
|
||||
const ValueType& operator*() const { return *reinterpret_cast<const ValueType*>(&ParentType::operator*()); }
|
||||
const ValueType* operator->() const { return reinterpret_cast<const ValueType*>(ParentType::operator->()); }
|
||||
const ValueType& operator*() const { return *reinterpret_cast<const ValueType*>(&RegexIteratorBase<Iterator>::operator*()); }
|
||||
const ValueType* operator->() const { return reinterpret_cast<const ValueType*>(RegexIteratorBase<Iterator>::operator->()); }
|
||||
};
|
||||
|
||||
inline RegexConstant::match_flag_type match_flags(bool bol, bool eol, bool bow, bool eow)
|
||||
|
@ -29,7 +29,7 @@ enum WordType { Word, WORD };
|
||||
template<WordType word_type = Word>
|
||||
inline bool is_word(Codepoint c)
|
||||
{
|
||||
return c == '_' or std::isalnum((wchar_t)c, std::locale{});
|
||||
return c == '_' or iswalnum((wchar_t)c);
|
||||
}
|
||||
|
||||
template<>
|
||||
@ -68,8 +68,8 @@ inline CharCategories categorize(Codepoint c)
|
||||
return CharCategories::Punctuation;
|
||||
}
|
||||
|
||||
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 Codepoint to_lower(Codepoint cp) { return towlower((wchar_t)cp); }
|
||||
inline Codepoint to_upper(Codepoint cp) { return towupper((wchar_t)cp); }
|
||||
|
||||
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; }
|
||||
|
Loading…
Reference in New Issue
Block a user