Pure virtual interface for String storage backends. More...
#include <stringdata.h>


Public Member Functions | |
| virtual StringData * | _promeki_clone () const =0 |
| Creates a deep copy of this storage backend. | |
| virtual | ~StringData () |
| Virtual destructor. | |
| bool | isEmpty () const |
| Returns true if the string has zero length. | |
| virtual uint64_t | hash () const =0 |
| Returns a 64-bit hash of the string data. | |
Character access | |
| virtual size_t | length () const =0 |
| Returns the number of characters in the string. | |
| virtual Char | charAt (size_t idx) const =0 |
| Returns the character at the given index. | |
| virtual void | setCharAt (size_t idx, Char ch)=0 |
| Sets the character at the given index. | |
| virtual bool | isLatin1 () const =0 |
| Returns true if the storage uses Latin1 encoding (one byte per character). | |
| virtual bool | isLiteral () const |
| Returns true if the storage wraps an immutable literal. | |
Substring / search | |
| virtual size_t | find (Char ch, size_t from=0) const =0 |
Finds the first occurrence of a character starting from from. | |
| virtual size_t | find (const StringData &s, size_t from=0) const =0 |
Finds the first occurrence of a substring starting from from. | |
| virtual size_t | rfind (Char ch, size_t from=npos) const =0 |
Finds the last occurrence of a character at or before from. | |
| virtual size_t | rfind (const StringData &s, size_t from=npos) const =0 |
Finds the last occurrence of a substring at or before from. | |
| virtual StringData * | createSubstr (size_t pos, size_t len) const =0 |
| Creates a new StringData containing a substring. | |
| virtual void | reverseInPlace ()=0 |
| Reverses the characters in place. | |
| virtual size_t | count (const StringData &substr) const =0 |
| Counts non-overlapping occurrences of a substring. | |
Mutation | |
| virtual void | append (const StringData &other)=0 |
| Appends another string's data to this storage. | |
| virtual void | append (Char ch)=0 |
| Appends a single character. | |
| virtual void | insert (size_t pos, const StringData &s)=0 |
| Inserts a string at the given position. | |
| virtual void | erase (size_t pos, size_t count)=0 |
| Erases characters from the string. | |
| virtual void | clear ()=0 |
| Removes all characters from the string. | |
| virtual void | resize (size_t len, Char fill=Char())=0 |
Resizes the string to len characters. | |
Byte-level output | |
| virtual size_t | byteCount () const =0 |
| Returns the byte count of the encoded string data. | |
| virtual uint8_t | byteAt (size_t idx) const =0 |
| Returns the byte at the given index. | |
| virtual const char * | cstr () const =0 |
| Returns a null-terminated C string pointer. | |
| virtual const std::string & | str () const =0 |
| Returns a const reference to the internal std::string representation. | |
Public Attributes | |
| RefCount | _promeki_refct |
| Manual reference count (PROMEKI_SHARED cannot be used on abstract classes). | |
Static Public Attributes | |
| static constexpr size_t | npos = static_cast<size_t>(-1) |
| Sentinel value indicating "not found". | |
Pure virtual interface for String storage backends.
StringData defines the contract that both Latin1 and Unicode storage implementations must satisfy. It manually provides RefCount and _promeki_clone() since PROMEKI_SHARED cannot be used on abstract classes.
|
pure virtual |
Creates a deep copy of this storage backend.
Implemented in StringLiteralData, and StringUnicodeLiteralData.
Appends a single character.
| ch | The character to append. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
|
pure virtual |
Appends another string's data to this storage.
| other | The data to append. |
Implemented in StringLiteralData, StringUnicodeLiteralData, StringLatin1Data, and StringUnicodeData.
Returns the byte at the given index.
| idx | Zero-based byte index. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Returns the byte count of the encoded string data.
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Returns the character at the given index.
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Removes all characters from the string.
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
|
pure virtual |
Counts non-overlapping occurrences of a substring.
| substr | The substring to count. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
|
pure virtual |
Creates a new StringData containing a substring.
| pos | Starting character index. |
| len | Number of characters. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Returns a null-terminated C string pointer.
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Erases characters from the string.
| pos | Starting character index. |
| count | Number of characters to erase. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Finds the first occurrence of a character starting from from.
| ch | The character to search for. |
| from | Starting character index. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
|
pure virtual |
Finds the first occurrence of a substring starting from from.
| s | The substring data to search for. |
| from | Starting character index. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Returns a 64-bit hash of the string data.
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
|
pure virtual |
Inserts a string at the given position.
| pos | Character index at which to insert. |
| s | The data to insert. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Returns true if the storage uses Latin1 encoding (one byte per character).
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Returns true if the storage wraps an immutable literal.
Reimplemented in StringLiteralData, and StringUnicodeLiteralData.
Returns the number of characters in the string.
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Resizes the string to len characters.
| len | New character count. |
| fill | Character used to pad if growing. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Reverses the characters in place.
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Finds the last occurrence of a character at or before from.
| ch | The character to search for. |
| from | Maximum character index to consider (npos = end). |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Finds the last occurrence of a substring at or before from.
| s | The substring data to search for. |
| from | Maximum character index to consider (npos = end). |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Sets the character at the given index.
| idx | Zero-based character index. |
| ch | The replacement character. |
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.
Returns a const reference to the internal std::string representation.
Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.