1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-19 01:11:36 +03:00

Add an operator[](CharCount) to String and StringView

This commit is contained in:
Maxime Coste 2014-08-11 19:40:35 +01:00
parent 43f44bbab3
commit 1b54b65bb5
3 changed files with 4 additions and 2 deletions

View File

@ -306,7 +306,7 @@ std::vector<String> list_files(StringView prefix, StringView dirname,
{ {
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode))
filename += '/'; filename += '/';
if (prefix.length() != 0 or filename[0] != '.') if (prefix.length() != 0 or filename[0_byte] != '.')
{ {
if (match_prefix) if (match_prefix)
result.push_back(filename); result.push_back(filename);

View File

@ -167,7 +167,7 @@ String read<String>(int socket)
if (length > 0) if (length > 0)
{ {
res.resize((int)length); res.resize((int)length);
read(socket, &res[0], (int)length); read(socket, &res[0_byte], (int)length);
} }
return res; return res;
} }

View File

@ -35,6 +35,7 @@ public:
char operator[](ByteCount pos) const { return std::string::operator[]((int)pos); } char operator[](ByteCount pos) const { return std::string::operator[]((int)pos); }
char& operator[](ByteCount pos) { return std::string::operator[]((int)pos); } char& operator[](ByteCount pos) { return std::string::operator[]((int)pos); }
Codepoint operator[](CharCount pos) { return utf8::codepoint(utf8::advance(begin(), end(), pos), end()); }
ByteCount length() const { return ByteCount{(int)std::string::length()}; } ByteCount length() const { return ByteCount{(int)std::string::length()}; }
CharCount char_length() const { return utf8::distance(begin(), end()); } CharCount char_length() const { return utf8::distance(begin(), end()); }
ByteCount byte_count_to(CharCount count) const { return utf8::advance(begin(), end(), (int)count) - begin(); } ByteCount byte_count_to(CharCount count) const { return utf8::advance(begin(), end(), (int)count) - begin(); }
@ -81,6 +82,7 @@ public:
char back() const { return m_data[(int)m_length - 1]; } char back() const { return m_data[(int)m_length - 1]; }
char operator[](ByteCount pos) const { return m_data[(int)pos]; } char operator[](ByteCount pos) const { return m_data[(int)pos]; }
Codepoint operator[](CharCount pos) { return utf8::codepoint(utf8::advance(begin(), end(), pos), end()); }
ByteCount length() const { return m_length; } ByteCount length() const { return m_length; }
CharCount char_length() const { return utf8::distance(begin(), end()); } CharCount char_length() const { return utf8::distance(begin(), end()); }