diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-05-19 21:45:23 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-05-19 21:45:23 +0100 |
| commit | 1834a67b87b7a8f6a9108721910e8be192471211 (patch) | |
| tree | 4784c9a83e7533b6afc2eaadf890fa9ca8ba952a /src | |
| parent | e1703204f8ca8e6cbc55ef609be99816ae5ec6d6 (diff) | |
Go back to libc locale and use c_regex_traits
Unfortunately, cygwin does not support c++ locales.
Diffstat (limited to 'src')
| -rw-r--r-- | src/highlighters.cc | 2 | ||||
| -rw-r--r-- | src/main.cc | 3 | ||||
| -rw-r--r-- | src/ranked_match.cc | 7 | ||||
| -rw-r--r-- | src/regex.cc | 2 | ||||
| -rw-r--r-- | src/regex.hh | 17 | ||||
| -rw-r--r-- | src/unicode.hh | 6 |
6 files changed, 19 insertions, 18 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc index bcab234e..fd1a4567 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -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); diff --git a/src/main.cc b/src/main.cc index fb4c16d1..4db4f883 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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); diff --git a/src/ranked_match.cc b/src/ranked_match.cc index 77025219..a6145d62 100644 --- a/src/ranked_match.cc +++ b/src/ranked_match.cc @@ -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) diff --git a/src/regex.cc b/src/regex.cc index d70d8dd6..4482cb59 100644 --- a/src/regex.cc +++ b/src/regex.cc @@ -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) diff --git a/src/regex.hh b/src/regex.hh index 9e966c33..f2457f4d 100644 --- a/src/regex.hh +++ b/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) diff --git a/src/unicode.hh b/src/unicode.hh index 83c63fa1..4ceeac74 100644 --- a/src/unicode.hh +++ b/src/unicode.hh @@ -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; } |
