add a unicode.hh header for Codepoint related functions, s/utf8::Codepoint/Codepoint/

This commit is contained in:
Maxime Coste 2012-10-09 19:15:05 +02:00
parent e1d4215159
commit 7a8366da2b
9 changed files with 47 additions and 35 deletions

View File

@ -3,6 +3,7 @@
#include "context.hh"
#include "editor.hh"
#include "register_manager.hh"
#include "utf8.hh"
#include <unordered_map>
@ -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);

View File

@ -16,7 +16,7 @@ Key canonicalize_ifn(Key key)
return key;
}
static std::unordered_map<String, utf8::Codepoint> keynamemap = {
static std::unordered_map<String, Codepoint> 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;
}

View File

@ -2,7 +2,7 @@
#define keys_hh_INCLUDED
#include <vector>
#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

View File

@ -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};

View File

@ -9,22 +9,11 @@
namespace Kakoune
{
using utf8::Codepoint;
using Utf8Iterator = utf8::utf8_iterator<BufferIterator>;
namespace
{
bool is_eol(Codepoint c)
{
return c == '\n';
}
bool is_blank(Codepoint c)
{
return c == ' ' or c == '\t';
}
template<bool punctuation_is_word = false>
bool is_word(Codepoint c)
{

View File

@ -18,16 +18,16 @@ SelectionAndCaptures select_line(const Selection& selection);
SelectionAndCaptures select_matching(const Selection& selection);
using CodepointPair = std::pair<utf8::Codepoint, utf8::Codepoint>;
using CodepointPair = std::pair<Codepoint, Codepoint>;
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);

View File

@ -83,14 +83,6 @@ String int_to_str(int value);
int str_to_int(const String& str);
std::vector<String> 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

32
src/unicode.hh Normal file
View File

@ -0,0 +1,32 @@
#ifndef unicode_hh_INCLUDED
#define unicode_hh_INCLUDED
#include <cstdint>
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

View File

@ -1,8 +1,8 @@
#ifndef utf8_hh_INCLUDED
#define utf8_hh_INCLUDED
#include <cstdint>
#include <cstddef>
#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<typename Iterator>
Iterator next(Iterator it)