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))
filename += '/';
if (prefix.length() != 0 or filename[0] != '.')
if (prefix.length() != 0 or filename[0_byte] != '.')
{
if (match_prefix)
result.push_back(filename);

View File

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

View File

@ -35,6 +35,7 @@ public:
char operator[](ByteCount pos) const { 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()}; }
CharCount char_length() const { return utf8::distance(begin(), end()); }
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 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; }
CharCount char_length() const { return utf8::distance(begin(), end()); }