1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:47:44 +00:00

AK: Add begin() and end() to String and StringView

Now it's possible to use range-based for loops with String and StringView.
This commit is contained in:
howar6hill 2020-03-10 16:13:29 +08:00 committed by Andreas Kling
parent a0e18f4450
commit e07f50c398
3 changed files with 15 additions and 6 deletions

View file

@ -34,6 +34,8 @@ namespace AK {
class StringView {
public:
using ConstIterator = const char*;
StringView() {}
StringView(const char* characters, size_t length)
: m_characters(characters)
@ -58,7 +60,10 @@ public:
bool is_empty() const { return m_length == 0; }
const char* characters_without_null_termination() const { return m_characters; }
size_t length() const { return m_length; }
char operator[](size_t index) const { return m_characters[index]; }
const char& operator[](size_t index) const { return m_characters[index]; }
ConstIterator begin() const { return characters_without_null_termination(); }
ConstIterator end() const { return begin() + length(); }
unsigned hash() const;