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

Unicode string storage. Decoded codepoints in a List<Char>. More...

#include <stringdata.h>

Inheritance diagram for StringUnicodeData:
Collaboration diagram for StringUnicodeData:

Public Member Functions

 StringUnicodeData ()
 Default constructor. Creates empty Unicode storage.
 
 StringUnicodeData (const List< Char > &chars)
 Constructs from a list of codepoints (copy).
 
 StringUnicodeData (List< Char > &&chars)
 Constructs from a list of codepoints (move).
 
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 idx, Char ch) override
 Sets the character at the given index.
 
bool isLatin1 () const override
 Returns true if the storage uses Latin1 encoding (one byte per character).
 
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 &other) override
 Appends another string's data to this storage.
 
void append (Char ch) override
 Appends a single character.
 
void insert (size_t pos, const StringData &s) override
 Inserts a string at the given position.
 
void erase (size_t pos, size_t count) override
 Erases characters from the string.
 
void clear () override
 Removes all characters from the string.
 
void resize (size_t len, Char fill=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_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 bool isLiteral () const
 Returns true if the storage wraps an immutable literal.
 

Static Public Member Functions

static StringUnicodeDatafromUtf8 (const char *data, size_t len)
 Creates a StringUnicodeData by decoding UTF-8 bytes.
 
static StringUnicodeDatafromLatin1 (const std::string &s)
 Creates a StringUnicodeData by promoting Latin1 bytes.
 

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

Unicode string storage. Decoded codepoints in a List<Char>.

All character positions are O(1) since codepoints are stored as fixed-width char32_t values. A UTF-8 encoded std::string is lazily cached for byte-level output.

Constructor & Destructor Documentation

◆ StringUnicodeData() [1/2]

StringUnicodeData::StringUnicodeData ( const List< Char > &  chars)
inline

Constructs from a list of codepoints (copy).

Parameters
charsThe decoded codepoints.

◆ StringUnicodeData() [2/2]

StringUnicodeData::StringUnicodeData ( List< Char > &&  chars)
inline

Constructs from a list of codepoints (move).

Parameters
charsThe decoded codepoints to move from.

Member Function Documentation

◆ append() [1/2]

void StringUnicodeData::append ( Char  ch)
overridevirtual

Appends a single character.

Parameters
chThe character to append.

Implements StringData.

◆ append() [2/2]

void StringUnicodeData::append ( const StringData other)
overridevirtual

Appends another string's data to this storage.

Parameters
otherThe data to append.

Implements StringData.

◆ byteAt()

uint8_t StringUnicodeData::byteAt ( size_t  idx) const
overridevirtual

Returns the byte at the given index.

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

Implements StringData.

◆ byteCount()

size_t StringUnicodeData::byteCount ( ) const
overridevirtual

Returns the byte count of the encoded string data.

Implements StringData.

◆ charAt()

Char StringUnicodeData::charAt ( size_t  idx) const
inlineoverridevirtual

Returns the character at the given index.

Implements StringData.

◆ clear()

void StringUnicodeData::clear ( )
overridevirtual

Removes all characters from the string.

Implements StringData.

◆ count()

size_t StringUnicodeData::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 * StringUnicodeData::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 * StringUnicodeData::cstr ( ) const
overridevirtual

Returns a null-terminated C string pointer.

Implements StringData.

◆ erase()

void StringUnicodeData::erase ( size_t  pos,
size_t  count 
)
overridevirtual

Erases characters from the string.

Parameters
posStarting character index.
countNumber of characters to erase.

Implements StringData.

◆ find() [1/2]

size_t StringUnicodeData::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 StringUnicodeData::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.

◆ fromLatin1()

static StringUnicodeData * StringUnicodeData::fromLatin1 ( const std::string &  s)
static

Creates a StringUnicodeData by promoting Latin1 bytes.

Parameters
sThe Latin1 string (each byte becomes a Char).
Returns
A new StringUnicodeData, caller takes ownership.

◆ fromUtf8()

static StringUnicodeData * StringUnicodeData::fromUtf8 ( const char data,
size_t  len 
)
static

Creates a StringUnicodeData by decoding UTF-8 bytes.

Parameters
dataPointer to UTF-8 encoded bytes.
lenNumber of bytes.
Returns
A new StringUnicodeData, caller takes ownership.

◆ hash()

uint64_t StringUnicodeData::hash ( ) const
overridevirtual

Returns a 64-bit hash of the string data.

Implements StringData.

◆ insert()

void StringUnicodeData::insert ( size_t  pos,
const StringData s 
)
overridevirtual

Inserts a string at the given position.

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

Implements StringData.

◆ isLatin1()

bool StringUnicodeData::isLatin1 ( ) const
inlineoverridevirtual

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

Implements StringData.

◆ length()

size_t StringUnicodeData::length ( ) const
inlineoverridevirtual

Returns the number of characters in the string.

Implements StringData.

◆ resize()

void StringUnicodeData::resize ( size_t  len,
Char  fill = Char() 
)
overridevirtual

Resizes the string to len characters.

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

Implements StringData.

◆ reverseInPlace()

void StringUnicodeData::reverseInPlace ( )
overridevirtual

Reverses the characters in place.

Implements StringData.

◆ rfind() [1/2]

size_t StringUnicodeData::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 StringUnicodeData::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 StringUnicodeData::setCharAt ( size_t  idx,
Char  ch 
)
overridevirtual

Sets the character at the given index.

Parameters
idxZero-based character index.
chThe replacement character.

Implements StringData.

◆ str()

const std::string & StringUnicodeData::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: