diff --git a/src/file.cc b/src/file.cc index c0ffd6435..7dab64ec3 100644 --- a/src/file.cc +++ b/src/file.cc @@ -306,7 +306,7 @@ std::vector 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); diff --git a/src/remote.cc b/src/remote.cc index d75e13dfa..a5643387d 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -167,7 +167,7 @@ String read(int socket) if (length > 0) { res.resize((int)length); - read(socket, &res[0], (int)length); + read(socket, &res[0_byte], (int)length); } return res; } diff --git a/src/string.hh b/src/string.hh index 91bdbc609..c6c403521 100644 --- a/src/string.hh +++ b/src/string.hh @@ -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()); }