From 4b0ccb0437576c2d87be07b9865ff78a1c5f0c15 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 1 Oct 2012 20:20:08 +0200 Subject: [PATCH] String and BufferIterator value_type goes back to plain char --- src/buffer.hh | 4 +-- src/buffer_iterator.inl.hh | 2 +- src/highlighters.cc | 2 +- src/string.cc | 2 +- src/string.hh | 63 +++++++++----------------------------- 5 files changed, 19 insertions(+), 54 deletions(-) diff --git a/src/buffer.hh b/src/buffer.hh index d75a37d5..5f16c0c1 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -31,7 +31,7 @@ struct BufferCoord : LineAndColumn class BufferIterator { public: - typedef Character value_type; + typedef char value_type; typedef size_t difference_type; typedef const value_type* pointer; typedef const value_type& reference; @@ -47,7 +47,7 @@ public: bool operator> (const BufferIterator& iterator) const; bool operator>= (const BufferIterator& iterator) const; - Character operator* () const; + char operator* () const; size_t operator- (const BufferIterator& iterator) const; BufferIterator operator+ (CharCount size) const; diff --git a/src/buffer_iterator.inl.hh b/src/buffer_iterator.inl.hh index 1b346527..0f4367ef 100644 --- a/src/buffer_iterator.inl.hh +++ b/src/buffer_iterator.inl.hh @@ -108,7 +108,7 @@ inline void BufferIterator::on_erase(const BufferCoord& begin, } -inline Character BufferIterator::operator*() const +inline char BufferIterator::operator*() const { assert(m_buffer); return m_buffer->m_lines[line()].content[column()]; diff --git a/src/highlighters.cc b/src/highlighters.cc index 3f267d53..fc8e9b13 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -122,7 +122,7 @@ HighlighterAndId colorize_regex_factory(Window& window, try { - static Regex color_spec_ex(LR"((\d+):(\w+(,\w+)?))"); + static Regex color_spec_ex(R"((\d+):(\w+(,\w+)?))"); ColorSpec colors; for (auto it = params.begin() + 1; it != params.end(); ++it) { diff --git a/src/string.cc b/src/string.cc index 042bba77..2152cb15 100644 --- a/src/string.cc +++ b/src/string.cc @@ -30,7 +30,7 @@ int str_to_int(const String& str) return atoi(str.c_str()); } -std::vector split(const String& str, Character separator) +std::vector split(const String& str, char separator) { auto begin = str.begin(); auto end = str.begin(); diff --git a/src/string.hh b/src/string.hh index 2e8172c1..31af1986 100644 --- a/src/string.hh +++ b/src/string.hh @@ -11,8 +11,8 @@ namespace Kakoune { -typedef wchar_t Character; -typedef boost::basic_regex Regex; +typedef int32_t Character; +typedef boost::regex Regex; class String { @@ -22,11 +22,11 @@ public: String(std::string content) : m_content(std::move(content)) {} String(const String& string) = default; String(String&& string) = default; - explicit String(Character content) : m_content(std::string() + (char)content) {} + explicit String(char content) : m_content(std::string() + content) {} template String(Iterator begin, Iterator end) : m_content(begin, end) {} - Character operator[](CharCount pos) const { return static_cast(m_content[(int)pos]); } + char operator[](CharCount pos) const { return m_content[(int)pos]; } CharCount length() const { return m_content.length(); } bool empty() const { return m_content.empty(); } @@ -40,8 +40,8 @@ public: String operator+ (const String& other) const { return String(m_content + other.m_content); } String& operator+= (const String& other) { m_content += other.m_content; return *this; } - String operator+ (Character character) const { return String(m_content + (char)character); } - String& operator+= (Character character) { m_content += (char)character; return *this; } + String operator+ (char c) const { return String(m_content + c); } + String& operator+= (char c) { m_content += c; return *this; } memoryview data() const { return memoryview(m_content.data(), m_content.size()); } const char* c_str() const { return m_content.c_str(); } @@ -49,50 +49,15 @@ public: String substr(CharCount pos, CharCount length = -1) const { return String(m_content.substr((int)pos, (int)length)); } String replace(const String& expression, const String& replacement) const; - class iterator - { - public: - typedef Character value_type; - typedef const value_type* pointer; - typedef const value_type& reference; - typedef size_t difference_type; - typedef std::random_access_iterator_tag iterator_category; + using iterator = std::string::const_iterator; - iterator() {} - iterator(const std::string::const_iterator& it) : m_iterator(it) {} + iterator begin() const { return m_content.begin(); } + iterator end() const { return m_content.end(); } - Character operator*() - { return static_cast(*m_iterator); } + char front() const { return m_content.front(); } + char back() const { return m_content.back(); } - iterator& operator++ () { ++m_iterator; return *this; } - iterator& operator-- () { --m_iterator; return *this; } - - iterator operator+ (size_t size) { return iterator(m_iterator + size); } - iterator operator- (size_t size) { return iterator(m_iterator - size); } - - iterator& operator+= (size_t size) { m_iterator += size; return *this; } - iterator& operator-= (size_t size) { m_iterator -= size; return *this; } - - size_t operator- (const iterator& other) const { return m_iterator - other.m_iterator; } - - bool operator== (const iterator& other) const { return m_iterator == other.m_iterator; } - bool operator!= (const iterator& other) const { return m_iterator != other.m_iterator; } - bool operator< (const iterator& other) const { return m_iterator < other.m_iterator; } - bool operator<= (const iterator& other) const { return m_iterator <= other.m_iterator; } - bool operator> (const iterator& other) const { return m_iterator > other.m_iterator; } - bool operator>= (const iterator& other) const { return m_iterator >= other.m_iterator; } - - private: - std::string::const_iterator m_iterator; - }; - - iterator begin() const { return iterator(m_content.begin()); } - iterator end() const { return iterator(m_content.end()); } - - Character front() const { return Character(m_content.front()); } - Character back() const { return Character(m_content.back()); } - - size_t hash() const { return std::hash()(m_content); } + size_t hash() const { return std::hash()(m_content); } inline friend std::ostream& operator<<(std::ostream& os, const String& str) { @@ -110,14 +75,14 @@ inline String operator+(const char* lhs, const String& rhs) return String(lhs) + rhs; } -inline String operator+(Character lhs, const String& rhs) +inline String operator+(char lhs, const String& rhs) { return String(lhs) + rhs; } String int_to_str(int value); int str_to_int(const String& str); -std::vector split(const String& str, Character separator); +std::vector split(const String& str, char separator); inline bool is_word(Character c) {