String and BufferIterator value_type goes back to plain char
This commit is contained in:
parent
f2f3421637
commit
4b0ccb0437
|
@ -31,7 +31,7 @@ struct BufferCoord : LineAndColumn<BufferCoord>
|
||||||
class BufferIterator
|
class BufferIterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef Character value_type;
|
typedef char value_type;
|
||||||
typedef size_t difference_type;
|
typedef size_t difference_type;
|
||||||
typedef const value_type* pointer;
|
typedef const value_type* pointer;
|
||||||
typedef const value_type& reference;
|
typedef const value_type& reference;
|
||||||
|
@ -47,7 +47,7 @@ public:
|
||||||
bool operator> (const BufferIterator& iterator) const;
|
bool operator> (const BufferIterator& iterator) const;
|
||||||
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;
|
size_t operator- (const BufferIterator& iterator) const;
|
||||||
|
|
||||||
BufferIterator operator+ (CharCount size) const;
|
BufferIterator operator+ (CharCount size) const;
|
||||||
|
|
|
@ -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);
|
assert(m_buffer);
|
||||||
return m_buffer->m_lines[line()].content[column()];
|
return m_buffer->m_lines[line()].content[column()];
|
||||||
|
|
|
@ -122,7 +122,7 @@ HighlighterAndId colorize_regex_factory(Window& window,
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
static Regex color_spec_ex(LR"((\d+):(\w+(,\w+)?))");
|
static Regex color_spec_ex(R"((\d+):(\w+(,\w+)?))");
|
||||||
ColorSpec colors;
|
ColorSpec colors;
|
||||||
for (auto it = params.begin() + 1; it != params.end(); ++it)
|
for (auto it = params.begin() + 1; it != params.end(); ++it)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,7 +30,7 @@ int str_to_int(const String& str)
|
||||||
return atoi(str.c_str());
|
return atoi(str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<String> split(const String& str, Character separator)
|
std::vector<String> split(const String& str, char separator)
|
||||||
{
|
{
|
||||||
auto begin = str.begin();
|
auto begin = str.begin();
|
||||||
auto end = str.begin();
|
auto end = str.begin();
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef wchar_t Character;
|
typedef int32_t Character;
|
||||||
typedef boost::basic_regex<Character> Regex;
|
typedef boost::regex Regex;
|
||||||
|
|
||||||
class String
|
class String
|
||||||
{
|
{
|
||||||
|
@ -22,11 +22,11 @@ public:
|
||||||
String(std::string content) : m_content(std::move(content)) {}
|
String(std::string content) : m_content(std::move(content)) {}
|
||||||
String(const String& string) = default;
|
String(const String& string) = default;
|
||||||
String(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<typename Iterator>
|
template<typename Iterator>
|
||||||
String(Iterator begin, Iterator end) : m_content(begin, end) {}
|
String(Iterator begin, Iterator end) : m_content(begin, end) {}
|
||||||
|
|
||||||
Character operator[](CharCount pos) const { return static_cast<Character>(m_content[(int)pos]); }
|
char operator[](CharCount pos) const { return m_content[(int)pos]; }
|
||||||
CharCount length() const { return m_content.length(); }
|
CharCount length() const { return m_content.length(); }
|
||||||
bool empty() const { return m_content.empty(); }
|
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) const { return String(m_content + other.m_content); }
|
||||||
String& operator+= (const String& other) { m_content += other.m_content; return *this; }
|
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+ (char c) const { return String(m_content + c); }
|
||||||
String& operator+= (Character character) { m_content += (char)character; return *this; }
|
String& operator+= (char c) { m_content += c; return *this; }
|
||||||
|
|
||||||
memoryview<char> data() const { return memoryview<char>(m_content.data(), m_content.size()); }
|
memoryview<char> data() const { return memoryview<char>(m_content.data(), m_content.size()); }
|
||||||
const char* c_str() const { return m_content.c_str(); }
|
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 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;
|
String replace(const String& expression, const String& replacement) const;
|
||||||
|
|
||||||
class iterator
|
using iterator = std::string::const_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;
|
|
||||||
|
|
||||||
iterator() {}
|
iterator begin() const { return m_content.begin(); }
|
||||||
iterator(const std::string::const_iterator& it) : m_iterator(it) {}
|
iterator end() const { return m_content.end(); }
|
||||||
|
|
||||||
Character operator*()
|
char front() const { return m_content.front(); }
|
||||||
{ return static_cast<Character>(*m_iterator); }
|
char back() const { return m_content.back(); }
|
||||||
|
|
||||||
iterator& operator++ () { ++m_iterator; return *this; }
|
size_t hash() const { return std::hash<std::string>()(m_content); }
|
||||||
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<std::string>()(m_content); }
|
|
||||||
|
|
||||||
inline friend std::ostream& operator<<(std::ostream& os, const String& str)
|
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;
|
return String(lhs) + rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline String operator+(Character lhs, const String& rhs)
|
inline String operator+(char lhs, const String& rhs)
|
||||||
{
|
{
|
||||||
return String(lhs) + rhs;
|
return String(lhs) + rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
String int_to_str(int value);
|
String int_to_str(int value);
|
||||||
int str_to_int(const String& str);
|
int str_to_int(const String& str);
|
||||||
std::vector<String> split(const String& str, Character separator);
|
std::vector<String> split(const String& str, char separator);
|
||||||
|
|
||||||
inline bool is_word(Character c)
|
inline bool is_word(Character c)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user