mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:07:45 +00:00
AK: Add a StringView class.
This commit is contained in:
parent
7972303405
commit
461aa550eb
2 changed files with 40 additions and 6 deletions
25
AK/StringView.h
Normal file
25
AK/StringView.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
class StringView {
|
||||
public:
|
||||
StringView() { }
|
||||
StringView(const char* characters, int length) : m_characters(characters), m_length(length) { }
|
||||
StringView(const unsigned char* characters, int length) : m_characters((const char*)characters), m_length(length) { }
|
||||
StringView(const char* cstring)
|
||||
: m_characters(cstring)
|
||||
{
|
||||
if (cstring) {
|
||||
while (*(cstring++))
|
||||
++m_length;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_empty() const { return m_length == 0; }
|
||||
const char* characters() const { return m_characters; }
|
||||
int length() const { return m_length; }
|
||||
char operator[](int index) const { return m_characters[index]; }
|
||||
|
||||
private:
|
||||
const char* m_characters { nullptr };
|
||||
int m_length { 0 };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue