From 7a8366da2b5f8149b0bd316ae0905c8453b36f62 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 9 Oct 2012 19:15:05 +0200 Subject: [PATCH] add a unicode.hh header for Codepoint related functions, s/utf8::Codepoint/Codepoint/ --- src/client.cc | 3 ++- src/keys.cc | 6 +++--- src/keys.hh | 10 +++++----- src/ncurses.cc | 2 +- src/selectors.cc | 11 ----------- src/selectors.hh | 6 +++--- src/string.hh | 8 -------- src/unicode.hh | 32 ++++++++++++++++++++++++++++++++ src/utf8.hh | 4 +--- 9 files changed, 47 insertions(+), 35 deletions(-) create mode 100644 src/unicode.hh diff --git a/src/client.cc b/src/client.cc index 6c06f465..11996f82 100644 --- a/src/client.cc +++ b/src/client.cc @@ -3,6 +3,7 @@ #include "context.hh" #include "editor.hh" #include "register_manager.hh" +#include "utf8.hh" #include @@ -393,7 +394,7 @@ private: int m_current_completion = -1; }; -String codepoint_to_str(utf8::Codepoint cp) +String codepoint_to_str(Codepoint cp) { std::string str; auto it = back_inserter(str); diff --git a/src/keys.cc b/src/keys.cc index 696b704e..18b31d77 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -16,7 +16,7 @@ Key canonicalize_ifn(Key key) return key; } -static std::unordered_map keynamemap = { +static std::unordered_map keynamemap = { { "ret", '\r' }, { "space", ' ' }, { "esc", Key::Escape } @@ -53,7 +53,7 @@ KeyList parse_keys(const String& str) } if (keyname.length() == 1) { - result.push_back(Key{ modifier, utf8::Codepoint(keyname[0]) }); + result.push_back(Key{ modifier, Codepoint(keyname[0]) }); pos = end_pos; continue; } @@ -67,7 +67,7 @@ KeyList parse_keys(const String& str) } } } - result.push_back({Key::Modifiers::None, utf8::Codepoint(str[pos])}); + result.push_back({Key::Modifiers::None, Codepoint(str[pos])}); } return result; } diff --git a/src/keys.hh b/src/keys.hh index 8355397f..76063eb6 100644 --- a/src/keys.hh +++ b/src/keys.hh @@ -2,7 +2,7 @@ #define keys_hh_INCLUDED #include -#include "utf8.hh" +#include "unicode.hh" #include "string.hh" namespace Kakoune @@ -17,7 +17,7 @@ struct Key Alt = 2, ControlAlt = 3 }; - enum NamedKey : utf8::Codepoint + enum NamedKey : Codepoint { // use UTF-16 surrogate pairs range Backspace = 0xD800, @@ -32,12 +32,12 @@ struct Key }; Modifiers modifiers; - utf8::Codepoint key; + Codepoint key; - constexpr Key(Modifiers modifiers, utf8::Codepoint key) + constexpr Key(Modifiers modifiers, Codepoint key) : modifiers(modifiers), key(key) {} - constexpr Key(utf8::Codepoint key) + constexpr Key(Codepoint key) : modifiers(Modifiers::None), key(key) {} constexpr bool operator==(const Key& other) const diff --git a/src/ncurses.cc b/src/ncurses.cc index 6dd3359c..68001876 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -197,7 +197,7 @@ Key NCursesUI::get_key() else if (c == 27) { timeout(0); - const utf8::Codepoint new_c = getch(); + const Codepoint new_c = getch(); timeout(-1); if (new_c != ERR) return {Key::Modifiers::Alt, new_c}; diff --git a/src/selectors.cc b/src/selectors.cc index bed7d23e..0a80f58d 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -9,22 +9,11 @@ namespace Kakoune { -using utf8::Codepoint; using Utf8Iterator = utf8::utf8_iterator; namespace { -bool is_eol(Codepoint c) -{ - return c == '\n'; -} - -bool is_blank(Codepoint c) -{ - return c == ' ' or c == '\t'; -} - template bool is_word(Codepoint c) { diff --git a/src/selectors.hh b/src/selectors.hh index fc6a628a..9cd10ba4 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -18,16 +18,16 @@ SelectionAndCaptures select_line(const Selection& selection); SelectionAndCaptures select_matching(const Selection& selection); -using CodepointPair = std::pair; +using CodepointPair = std::pair; SelectionAndCaptures select_surrounding(const Selection& selection, const CodepointPair& matching, bool inside); SelectionAndCaptures select_to(const Selection& selection, - utf8::Codepoint c, + Codepoint c, int count, bool inclusive); SelectionAndCaptures select_to_reverse(const Selection& selection, - utf8::Codepoint c, + Codepoint c, int count, bool inclusive); SelectionAndCaptures select_to_eol(const Selection& selection); diff --git a/src/string.hh b/src/string.hh index ad3a7b5f..dfcd9cbb 100644 --- a/src/string.hh +++ b/src/string.hh @@ -83,14 +83,6 @@ String int_to_str(int value); int str_to_int(const String& str); std::vector split(const String& str, char separator); -inline bool is_word(char c) -{ - return (c >= '0' and c <= '9') or - (c >= 'a' and c <= 'z') or - (c >= 'A' and c <= 'Z') or - c == '_'; -} - } namespace std diff --git a/src/unicode.hh b/src/unicode.hh new file mode 100644 index 00000000..8da688e4 --- /dev/null +++ b/src/unicode.hh @@ -0,0 +1,32 @@ +#ifndef unicode_hh_INCLUDED +#define unicode_hh_INCLUDED + +#include + +namespace Kakoune +{ + +using Codepoint = uint32_t; + +inline bool is_word(Codepoint c) +{ + return (c >= '0' and c <= '9') or + (c >= 'a' and c <= 'z') or + (c >= 'A' and c <= 'Z') or + c == '_'; +} + +inline bool is_eol(Codepoint c) +{ + return c == '\n'; +} + +inline bool is_blank(Codepoint c) +{ + return c == ' ' or c == '\t'; +} + +} + +#endif // unicode_hh_INCLUDED + diff --git a/src/utf8.hh b/src/utf8.hh index 6bc29942..122c71ae 100644 --- a/src/utf8.hh +++ b/src/utf8.hh @@ -1,8 +1,8 @@ #ifndef utf8_hh_INCLUDED #define utf8_hh_INCLUDED -#include #include +#include "unicode.hh" namespace Kakoune { @@ -10,8 +10,6 @@ namespace Kakoune namespace utf8 { -using Codepoint = uint32_t; - // returns an iterator to next character first byte template Iterator next(Iterator it)