Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::ChunkedString Class Reference

ChunkedString is a small helper to accumulate multiple RcStringOrRef pieces, either as small appended fragments or single codepoints. More...

#include "donner/base/ChunkedString.h"

Public Member Functions

 ChunkedString ()=default
 Default constructor.
 
 ChunkedString (std::string_view sv)
 Constructor from a string_view.
 
 ChunkedString (const RcString &str)
 Constructor from an RcString.
 
 ChunkedString (const RcStringOrRef &str)
 Constructor from an RcStringOrRef.
 
 ChunkedString (const char *str)
 Constructor from a C-style string.
 
 ChunkedString (const ChunkedString &other)
 Copy constructor from another ChunkedString.
 
ChunkedStringoperator= (const ChunkedString &other)
 Assignment operator.
 
void append (std::string_view sv)
 Appends a string_view as a piece reference.
 
void appendLiteral (const char *str)
 Helper method to append a C-style string literal.
 
void append (const RcStringOrRef &piece)
 Appends an RcStringOrRef by-value (moves in the reference).
 
void append (const RcString &piece)
 Appends an RcString.
 
void append (const ChunkedString &other)
 Append another ChunkedString.
 
void prepend (std::string_view sv)
 Prepends a string_view at the beginning of the chunks.
 
void prependLiteral (const char *str)
 Helper method to prepend a C-style string literal.
 
void prepend (const RcStringOrRef &piece)
 Prepends an RcStringOrRef by-value at the beginning of the chunks.
 
void prepend (const RcString &piece)
 Prepends an RcString at the beginning of the chunks.
 
void prepend (const ChunkedString &other)
 Prepends another ChunkedString at the beginning of the chunks.
 
RcString toSingleRcString () const
 Flattens all the pieces into one single RcStringOrRef.
 
std::string_view firstChunk () const
 Return the first chunk as a string_view.
 
size_t size () const
 Return the total length of the string.
 
size_t numChunks () const
 Return the number of chunks in the string.
 
bool empty () const
 Checks if the string is empty.
 
char operator[] (size_t pos) const
 Access the character at the specified position.
 
ChunkedString substr (size_t pos, size_t count=std::string_view::npos) const
 Returns a substring of this string.
 
void remove_prefix (size_t n)
 Removes the first n characters from the string.
 
bool starts_with (std::string_view prefix) const
 Checks if the string starts with the given prefix.
 
bool operator== (const ChunkedString &other) const
 Equality operator to compare with another ChunkedString.
 
bool operator== (std::string_view sv) const
 Equality operator to compare with a string_view.
 
bool operator== (const RcString &str) const
 Equality operator to compare with an RcString.
 
bool operator== (const RcStringOrRef &str) const
 Equality operator to compare with an RcStringOrRef.
 
bool operator== (const char *str) const
 Equality operator to compare with a C-style string.
 
bool ends_with (std::string_view suffix) const
 Checks if the string ends with the given suffix.
 
size_t find (std::string_view s, size_t pos=0) const
 Finds the first occurrence of a substring.
 

Friends

bool operator== (std::string_view sv, const ChunkedString &cs)
 Friend functions to allow reversed equality syntax.
 
bool operator== (const RcString &str, const ChunkedString &cs)
 
bool operator== (const RcStringOrRef &str, const ChunkedString &cs)
 
bool operator== (const char *str, const ChunkedString &cs)
 
std::ostream & operator<< (std::ostream &os, const ChunkedString &cs)
 Stream insertion operator.
 

Detailed Description

ChunkedString is a small helper to accumulate multiple RcStringOrRef pieces, either as small appended fragments or single codepoints.

It can optionally flatten them all into a single RcString if needed.

Constructor & Destructor Documentation

◆ ChunkedString() [1/5]

donner::ChunkedString::ChunkedString ( std::string_view sv)
inlineexplicit

Constructor from a string_view.

This is a zero-copy operation, referencing the underlying memory (if still alive).

Parameters
svThe string_view to initialize with.

◆ ChunkedString() [2/5]

donner::ChunkedString::ChunkedString ( const RcString & str)
inlineexplicit

Constructor from an RcString.

Parameters
strThe RcString to initialize with.

◆ ChunkedString() [3/5]

donner::ChunkedString::ChunkedString ( const RcStringOrRef & str)
inlineexplicit

Constructor from an RcStringOrRef.

Parameters
strThe RcStringOrRef to initialize with.

◆ ChunkedString() [4/5]

donner::ChunkedString::ChunkedString ( const char * str)
inlineexplicit

Constructor from a C-style string.

Parameters
strThe C-style string to initialize with.

◆ ChunkedString() [5/5]

donner::ChunkedString::ChunkedString ( const ChunkedString & other)
inline

Copy constructor from another ChunkedString.

Parameters
otherThe ChunkedString to copy from.

Member Function Documentation

◆ append()

void donner::ChunkedString::append ( std::string_view sv)
inline

Appends a string_view as a piece reference.

This is a zero-copy operation, referencing the underlying memory (if still alive).

◆ appendLiteral()

void donner::ChunkedString::appendLiteral ( const char * str)
inline

Helper method to append a C-style string literal.

This resolves the ambiguity between the string_view, RcString, and RcStringOrRef overloads when passing string literals.

Parameters
strThe string literal to append.

◆ empty()

bool donner::ChunkedString::empty ( ) const
inline

Checks if the string is empty.

Returns
true if the string is empty, false otherwise.

◆ ends_with()

bool donner::ChunkedString::ends_with ( std::string_view suffix) const
inline

Checks if the string ends with the given suffix.

Parameters
suffixThe suffix to check for.
Returns
true if the string ends with the suffix, false otherwise.

◆ find()

size_t donner::ChunkedString::find ( std::string_view s,
size_t pos = 0 ) const
inline

Finds the first occurrence of a substring.

Parameters
sThe substring to find.
posThe position to start searching from.
Returns
The position of the found substring, or npos if not found.

◆ operator=()

ChunkedString & donner::ChunkedString::operator= ( const ChunkedString & other)
inline

Assignment operator.

Parameters
otherThe ChunkedString to assign from.
Returns
A reference to this ChunkedString.

◆ operator==() [1/5]

bool donner::ChunkedString::operator== ( const char * str) const
inline

Equality operator to compare with a C-style string.

Parameters
strThe C-style string to compare with.
Returns
true if the strings are equal, false otherwise.

◆ operator==() [2/5]

bool donner::ChunkedString::operator== ( const ChunkedString & other) const
inline

Equality operator to compare with another ChunkedString.

Parameters
otherThe ChunkedString to compare with.
Returns
true if the strings are equal, false otherwise.

◆ operator==() [3/5]

bool donner::ChunkedString::operator== ( const RcString & str) const
inline

Equality operator to compare with an RcString.

Parameters
strThe RcString to compare with.
Returns
true if the strings are equal, false otherwise.

◆ operator==() [4/5]

bool donner::ChunkedString::operator== ( const RcStringOrRef & str) const
inline

Equality operator to compare with an RcStringOrRef.

Parameters
strThe RcStringOrRef to compare with.
Returns
true if the strings are equal, false otherwise.

◆ operator==() [5/5]

bool donner::ChunkedString::operator== ( std::string_view sv) const
inline

Equality operator to compare with a string_view.

Parameters
svThe string_view to compare with.
Returns
true if the strings are equal, false otherwise.

◆ operator[]()

char donner::ChunkedString::operator[] ( size_t pos) const
inline

Access the character at the specified position.

Note: This operation may be slow for large strings with many chunks, as it needs to find the chunk containing the specified position.

Parameters
posPosition of the character to access.
Returns
The character at the specified position.
Note
Behavior is undefined if pos is out of range.

◆ prepend()

void donner::ChunkedString::prepend ( std::string_view sv)
inline

Prepends a string_view at the beginning of the chunks.

This is a zero-copy operation, referencing the underlying memory (if still alive).

◆ prependLiteral()

void donner::ChunkedString::prependLiteral ( const char * str)
inline

Helper method to prepend a C-style string literal.

This resolves the ambiguity between the string_view, RcString, and RcStringOrRef overloads when passing string literals.

Parameters
strThe string literal to prepend.

◆ remove_prefix()

void donner::ChunkedString::remove_prefix ( size_t n)
inline

Removes the first n characters from the string.

Parameters
nNumber of characters to remove.

◆ starts_with()

bool donner::ChunkedString::starts_with ( std::string_view prefix) const
inline

Checks if the string starts with the given prefix.

Parameters
prefixThe prefix to check for.
Returns
true if the string starts with the prefix, false otherwise.

◆ substr()

ChunkedString donner::ChunkedString::substr ( size_t pos,
size_t count = std::string_view::npos ) const
inline

Returns a substring of this string.

Parameters
posPosition of the first character to include.
countNumber of characters to include.
Returns
A new string containing the specified substring.
Note
Behavior is undefined if pos is out of range.

◆ toSingleRcString()

RcString donner::ChunkedString::toSingleRcString ( ) const
inline

Flattens all the pieces into one single RcStringOrRef.

If there's only one piece, returns it directly; if empty, returns an empty piece. Otherwise, merges them into a newly allocated RcString and returns that.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const ChunkedString & cs )
friend

Stream insertion operator.

Parameters
osThe output stream.
csThe ChunkedString to output.
Returns
The output stream.

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