libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
StringLiteralData Class Reference

Immutable string storage wrapping a string literal pointer. More...

#include <stringdata.h>

Inheritance diagram for StringLiteralData:
Collaboration diagram for StringLiteralData:

Public Member Functions

 StringLiteralData (const char *s, size_t len, uint64_t precomputedHash=0)
 Constructs from a string literal pointer.
 
StringData_promeki_clone () const override
 Creates a deep copy of this storage backend.
 
size_t length () const override
 Returns the number of characters in the string.
 
Char charAt (size_t idx) const override
 Returns the character at the given index.
 
void setCharAt (size_t, Char) override
 Sets the character at the given index.
 
bool isLatin1 () const override
 Returns true if the storage uses Latin1 encoding (one byte per character).
 
bool isLiteral () const override
 Returns true if the storage wraps an immutable literal.
 
size_t find (Char ch, size_t from=0) const override
 Finds the first occurrence of a character starting from from.
 
size_t find (const StringData &s, size_t from=0) const override
 Finds the first occurrence of a substring starting from from.
 
size_t rfind (Char ch, size_t from=npos) const override
 Finds the last occurrence of a character at or before from.
 
size_t rfind (const StringData &s, size_t from=npos) const override
 Finds the last occurrence of a substring at or before from.
 
StringDatacreateSubstr (size_t pos, size_t len) const override
 Creates a new StringData containing a substring.
 
void reverseInPlace () override
 Reverses the characters in place.
 
size_t count (const StringData &substr) const override
 Counts non-overlapping occurrences of a substring.
 
void append (const StringData &) override
 Appends another string's data to this storage.
 
void append (Char) override
 Appends a single character.
 
void insert (size_t, const StringData &) override
 Inserts a string at the given position.
 
void erase (size_t, size_t) override
 Erases characters from the string.
 
void clear () override
 Removes all characters from the string.
 
void resize (size_t, Char) override
 Resizes the string to len characters.
 
size_t byteCount () const override
 Returns the byte count of the encoded string data.
 
uint8_t byteAt (size_t idx) const override
 Returns the byte at the given index.
 
const charcstr () const override
 Returns a null-terminated C string pointer.
 
const std::string & str () const override
 Returns a const reference to the internal std::string representation.
 
uint64_t hash () const override
 Returns a 64-bit hash of the string data.
 
- Public Member Functions inherited from StringData
virtual ~StringData ()
 Virtual destructor.
 
bool isEmpty () const
 Returns true if the string has zero length.
 

Additional Inherited Members

- Public Attributes inherited from StringData
RefCount _promeki_refct
 Manual reference count (PROMEKI_SHARED cannot be used on abstract classes).
 
- Static Public Attributes inherited from StringData
static constexpr size_t npos = static_cast<size_t>(-1)
 Sentinel value indicating "not found".
 

Detailed Description

Immutable string storage wrapping a string literal pointer.

No copy of the string data is made. The refcount is immortal so the object is never deleted — it lives in static storage at each call site via PROMEKI_STRING. COW always clones to a StringLatin1Data before any mutation.

Constructor & Destructor Documentation

◆ StringLiteralData()

StringLiteralData::StringLiteralData ( const char s,
size_t  len,
uint64_t  precomputedHash = 0 
)
inline

Constructs from a string literal pointer.

Parameters
sPointer to the literal data (must remain valid for the lifetime of this object).
lenLength of the literal in bytes.
precomputedHashOptional pre-computed FNV-1a hash (0 = compute on construction).

Member Function Documentation

◆ _promeki_clone()

StringData * StringLiteralData::_promeki_clone ( ) const
inlineoverridevirtual

Creates a deep copy of this storage backend.

Implements StringData.

◆ append() [1/2]

void StringLiteralData::append ( Char  ch)
inlineoverridevirtual

Appends a single character.

Parameters
chThe character to append.

Implements StringData.

◆ append() [2/2]

void StringLiteralData::append ( const StringData other)
inlineoverridevirtual

Appends another string's data to this storage.

Parameters
otherThe data to append.

Implements StringData.

◆ byteAt()

uint8_t StringLiteralData::byteAt ( size_t  idx) const
inlineoverridevirtual

Returns the byte at the given index.

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

Implements StringData.

◆ byteCount()

size_t StringLiteralData::byteCount ( ) const
inlineoverridevirtual

Returns the byte count of the encoded string data.

Implements StringData.

◆ charAt()

Char StringLiteralData::charAt ( size_t  idx) const
inlineoverridevirtual

Returns the character at the given index.

Implements StringData.

◆ clear()

void StringLiteralData::clear ( )
inlineoverridevirtual

Removes all characters from the string.

Implements StringData.

◆ count()

size_t StringLiteralData::count ( const StringData substr) const
overridevirtual

Counts non-overlapping occurrences of a substring.

Parameters
substrThe substring to count.
Returns
Number of occurrences.

Implements StringData.

◆ createSubstr()

StringData * StringLiteralData::createSubstr ( size_t  pos,
size_t  len 
) const
overridevirtual

Creates a new StringData containing a substring.

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

Implements StringData.

◆ cstr()

const char * StringLiteralData::cstr ( ) const
inlineoverridevirtual

Returns a null-terminated C string pointer.

Implements StringData.

◆ erase()

void StringLiteralData::erase ( size_t  pos,
size_t  count 
)
inlineoverridevirtual

Erases characters from the string.

Parameters
posStarting character index.
countNumber of characters to erase.

Implements StringData.

◆ find() [1/2]

size_t StringLiteralData::find ( Char  ch,
size_t  from = 0 
) const
overridevirtual

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.

Implements StringData.

◆ find() [2/2]

size_t StringLiteralData::find ( const StringData s,
size_t  from = 0 
) const
overridevirtual

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.

Implements StringData.

◆ hash()

uint64_t StringLiteralData::hash ( ) const
inlineoverridevirtual

Returns a 64-bit hash of the string data.

Implements StringData.

◆ insert()

void StringLiteralData::insert ( size_t  pos,
const StringData s 
)
inlineoverridevirtual

Inserts a string at the given position.

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

Implements StringData.

◆ isLatin1()

bool StringLiteralData::isLatin1 ( ) const
inlineoverridevirtual

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

Implements StringData.

◆ isLiteral()

bool StringLiteralData::isLiteral ( ) const
inlineoverridevirtual

Returns true if the storage wraps an immutable literal.

Reimplemented from StringData.

◆ length()

size_t StringLiteralData::length ( ) const
inlineoverridevirtual

Returns the number of characters in the string.

Implements StringData.

◆ resize()

void StringLiteralData::resize ( size_t  len,
Char  fill 
)
inlineoverridevirtual

Resizes the string to len characters.

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

Implements StringData.

◆ reverseInPlace()

void StringLiteralData::reverseInPlace ( )
inlineoverridevirtual

Reverses the characters in place.

Implements StringData.

◆ rfind() [1/2]

size_t StringLiteralData::rfind ( Char  ch,
size_t  from = npos 
) const
overridevirtual

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.

Implements StringData.

◆ rfind() [2/2]

size_t StringLiteralData::rfind ( const StringData s,
size_t  from = npos 
) const
overridevirtual

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.

Implements StringData.

◆ setCharAt()

void StringLiteralData::setCharAt ( size_t  idx,
Char  ch 
)
inlineoverridevirtual

Sets the character at the given index.

Parameters
idxZero-based character index.
chThe replacement character.

Implements StringData.

◆ str()

const std::string & StringLiteralData::str ( ) const
overridevirtual

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

Implements StringData.


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