libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
StringData Class Referenceabstract

Pure virtual interface for String storage backends. More...

#include <stringdata.h>

Inheritance diagram for StringData:
Collaboration diagram for StringData:

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 StringDatacreateSubstr (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 charcstr () 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".
 

Detailed Description

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.

Member Function Documentation

◆ _promeki_clone()

virtual StringData * StringData::_promeki_clone ( ) const
pure virtual

Creates a deep copy of this storage backend.

Implemented in StringLiteralData, and StringUnicodeLiteralData.

◆ append() [1/2]

virtual void StringData::append ( Char  ch)
pure virtual

Appends a single character.

Parameters
chThe character to append.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ append() [2/2]

virtual void StringData::append ( const StringData other)
pure virtual

Appends another string's data to this storage.

Parameters
otherThe data to append.

Implemented in StringLiteralData, StringUnicodeLiteralData, StringLatin1Data, and StringUnicodeData.

◆ byteAt()

virtual uint8_t StringData::byteAt ( size_t  idx) const
pure virtual

Returns the byte at the given index.

Parameters
idxZero-based byte index.
Returns
The byte value.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ byteCount()

virtual size_t StringData::byteCount ( ) const
pure virtual

Returns the byte count of the encoded string data.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ charAt()

virtual Char StringData::charAt ( size_t  idx) const
pure virtual

Returns the character at the given index.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ clear()

virtual void StringData::clear ( )
pure virtual

Removes all characters from the string.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ count()

virtual size_t StringData::count ( const StringData substr) const
pure virtual

Counts non-overlapping occurrences of a substring.

Parameters
substrThe substring to count.
Returns
Number of occurrences.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ createSubstr()

virtual StringData * StringData::createSubstr ( size_t  pos,
size_t  len 
) const
pure virtual

Creates a new StringData containing a substring.

Parameters
posStarting character index.
lenNumber of characters.
Returns
A newly allocated StringData; caller takes ownership.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ cstr()

virtual const char * StringData::cstr ( ) const
pure virtual

Returns a null-terminated C string pointer.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ erase()

virtual void StringData::erase ( size_t  pos,
size_t  count 
)
pure virtual

Erases characters from the string.

Parameters
posStarting character index.
countNumber of characters to erase.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ find() [1/2]

virtual size_t StringData::find ( Char  ch,
size_t  from = 0 
) const
pure virtual

Finds the first occurrence of a character starting from from.

Parameters
chThe character to search for.
fromStarting character index.
Returns
Character index of the match, or npos if not found.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ find() [2/2]

virtual size_t StringData::find ( const StringData s,
size_t  from = 0 
) const
pure virtual

Finds the first occurrence of a substring starting from from.

Parameters
sThe substring data to search for.
fromStarting character index.
Returns
Character index of the match, or npos if not found.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ hash()

virtual uint64_t StringData::hash ( ) const
pure virtual

Returns a 64-bit hash of the string data.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ insert()

virtual void StringData::insert ( size_t  pos,
const StringData s 
)
pure virtual

Inserts a string at the given position.

Parameters
posCharacter index at which to insert.
sThe data to insert.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ isLatin1()

virtual bool StringData::isLatin1 ( ) const
pure virtual

Returns true if the storage uses Latin1 encoding (one byte per character).

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ isLiteral()

virtual bool StringData::isLiteral ( ) const
inlinevirtual

Returns true if the storage wraps an immutable literal.

Reimplemented in StringLiteralData, and StringUnicodeLiteralData.

◆ length()

virtual size_t StringData::length ( ) const
pure virtual

Returns the number of characters in the string.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ resize()

virtual void StringData::resize ( size_t  len,
Char  fill = Char() 
)
pure virtual

Resizes the string to len characters.

Parameters
lenNew character count.
fillCharacter used to pad if growing.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ reverseInPlace()

virtual void StringData::reverseInPlace ( )
pure virtual

Reverses the characters in place.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ rfind() [1/2]

virtual size_t StringData::rfind ( Char  ch,
size_t  from = npos 
) const
pure virtual

Finds the last occurrence of a character at or before from.

Parameters
chThe character to search for.
fromMaximum character index to consider (npos = end).
Returns
Character index of the match, or npos if not found.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ rfind() [2/2]

virtual size_t StringData::rfind ( const StringData s,
size_t  from = npos 
) const
pure virtual

Finds the last occurrence of a substring at or before from.

Parameters
sThe substring data to search for.
fromMaximum character index to consider (npos = end).
Returns
Character index of the match, or npos if not found.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ setCharAt()

virtual void StringData::setCharAt ( size_t  idx,
Char  ch 
)
pure virtual

Sets the character at the given index.

Parameters
idxZero-based character index.
chThe replacement character.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.

◆ str()

virtual const std::string & StringData::str ( ) const
pure virtual

Returns a const reference to the internal std::string representation.

Implemented in StringLatin1Data, StringUnicodeData, StringLiteralData, and StringUnicodeLiteralData.


The documentation for this class was generated from the following file: