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

Immutable Unicode string storage wrapping compile-time decoded data. More...

#include <stringdata.h>

Inheritance diagram for StringUnicodeLiteralData:
Collaboration diagram for StringUnicodeLiteralData:

Public Member Functions

 StringUnicodeLiteralData (const char32_t *codepoints, size_t charCount, const char *bytes, size_t byteLen, uint64_t precomputedHash=0)
 Constructs from pre-decoded codepoints and original UTF-8 bytes.
 
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 Unicode string storage wrapping compile-time decoded data.

Wraps pointers to a pre-decoded char32_t codepoint array and the original UTF-8 bytes — both live in CompiledString's constexpr static storage. The refcount is immortal so the object is never deleted. COW always clones to a StringUnicodeData before mutation.

Constructor & Destructor Documentation

◆ StringUnicodeLiteralData()

StringUnicodeLiteralData::StringUnicodeLiteralData ( const char32_t codepoints,
size_t  charCount,
const char bytes,
size_t  byteLen,
uint64_t  precomputedHash = 0 
)
inline

Constructs from pre-decoded codepoints and original UTF-8 bytes.

Parameters
codepointsPointer to decoded char32_t array (must remain valid for the lifetime of this object).
charCountNumber of codepoints.
bytesPointer to original UTF-8 bytes (must remain valid for the lifetime of this object).
byteLenLength of the UTF-8 data in bytes.
precomputedHashOptional pre-computed FNV-1a hash (0 = compute on construction).

Member Function Documentation

◆ _promeki_clone()

StringData * StringUnicodeLiteralData::_promeki_clone ( ) const
overridevirtual

Creates a deep copy of this storage backend.

Implements StringData.

◆ append() [1/2]

void StringUnicodeLiteralData::append ( Char  ch)
inlineoverridevirtual

Appends a single character.

Parameters
chThe character to append.

Implements StringData.

◆ append() [2/2]

void StringUnicodeLiteralData::append ( const StringData other)
inlineoverridevirtual

Appends another string's data to this storage.

Parameters
otherThe data to append.

Implements StringData.

◆ byteAt()

uint8_t StringUnicodeLiteralData::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 StringUnicodeLiteralData::byteCount ( ) const
inlineoverridevirtual

Returns the byte count of the encoded string data.

Implements StringData.

◆ charAt()

Char StringUnicodeLiteralData::charAt ( size_t  idx) const
inlineoverridevirtual

Returns the character at the given index.

Implements StringData.

◆ clear()

void StringUnicodeLiteralData::clear ( )
inlineoverridevirtual

Removes all characters from the string.

Implements StringData.

◆ count()

size_t StringUnicodeLiteralData::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 * StringUnicodeLiteralData::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 * StringUnicodeLiteralData::cstr ( ) const
inlineoverridevirtual

Returns a null-terminated C string pointer.

Implements StringData.

◆ erase()

void StringUnicodeLiteralData::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 StringUnicodeLiteralData::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 StringUnicodeLiteralData::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 StringUnicodeLiteralData::hash ( ) const
inlineoverridevirtual

Returns a 64-bit hash of the string data.

Implements StringData.

◆ insert()

void StringUnicodeLiteralData::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 StringUnicodeLiteralData::isLatin1 ( ) const
inlineoverridevirtual

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

Implements StringData.

◆ isLiteral()

bool StringUnicodeLiteralData::isLiteral ( ) const
inlineoverridevirtual

Returns true if the storage wraps an immutable literal.

Reimplemented from StringData.

◆ length()

size_t StringUnicodeLiteralData::length ( ) const
inlineoverridevirtual

Returns the number of characters in the string.

Implements StringData.

◆ resize()

void StringUnicodeLiteralData::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 StringUnicodeLiteralData::reverseInPlace ( )
inlineoverridevirtual

Reverses the characters in place.

Implements StringData.

◆ rfind() [1/2]

size_t StringUnicodeLiteralData::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 StringUnicodeLiteralData::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 StringUnicodeLiteralData::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 & StringUnicodeLiteralData::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: