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

Encoding-aware string class with copy-on-write semantics. More...

#include <string.h>

Classes

class  CharIterator
 Random-access iterator over characters (Char values). More...
 

Public Types

enum  Encoding { Latin1 , Unicode }
 String encoding. More...
 
using List = promeki::List< String >
 List of Strings.
 
using ConstIterator = CharIterator
 Const character iterator.
 

Public Member Functions

 String ()
 Default constructor. Creates an empty Latin1 string.
 
 String (std::nullptr_t)
 Constructs an empty string (null pointer overload).
 
 String (const char *str)
 Constructs from a null-terminated C string.
 
 String (const char *str, size_t len)
 Constructs from a character buffer with explicit length.
 
 String (size_t ct, char c)
 Constructs a string of repeated characters.
 
 String (const std::string &str)
 Constructs from a std::string (copy).
 
 String (std::string &&str)
 Constructs from a std::string (move).
 
const std::string & str () const
 Returns a const reference to the underlying std::string.
 
const charcstr () const
 Returns a null-terminated C string pointer.
 
size_t size () const
 Returns the number of characters in the string.
 
size_t length () const
 Returns the number of characters in the string.
 
size_t byteCount () const
 Returns the number of bytes in the encoded representation.
 
uint8_t byteAt (size_t idx) const
 Returns the byte at the given index.
 
Char charAt (size_t idx) const
 Returns the character at the given index.
 
bool isEmpty () const
 Returns true if the string has zero length.
 
int referenceCount () const
 Returns the current shared reference count.
 
bool isLiteral () const
 Returns true if this string wraps an immutable literal.
 
Encoding encoding () const
 Returns the encoding of this string (Latin1 or Unicode).
 
ConstIterator begin () const noexcept
 Returns a const character iterator to the first character.
 
ConstIterator cbegin () const noexcept
 Returns a const character iterator to the first character.
 
ConstIterator end () const noexcept
 Returns a const character iterator past the last character.
 
ConstIterator cend () const noexcept
 Returns a const character iterator past the last character.
 
 operator const std::string & () const
 Implicit conversion to const std::string reference.
 
 operator const char * () const
 Implicit conversion to const char pointer.
 
size_t find (char val, size_t from=0) const
 Finds the first occurrence of a character.
 
size_t find (Char val, size_t from=0) const
 Finds the first occurrence of a character.
 
size_t find (const char *val, size_t from=0) const
 Finds the first occurrence of a character.
 
size_t find (const String &val, size_t from=0) const
 Finds the first occurrence of a character.
 
size_t rfind (char val, size_t from=npos) const
 Finds the last occurrence of a character.
 
size_t rfind (Char val, size_t from=npos) const
 Finds the last occurrence of a character.
 
size_t rfind (const char *val, size_t from=npos) const
 Finds the last occurrence of a character.
 
size_t rfind (const String &val, size_t from=npos) const
 Finds the last occurrence of a character.
 
bool contains (char val) const
 Returns true if the string contains the given value.
 
bool contains (Char val) const
 Returns true if the string contains the given value.
 
bool contains (const String &val) const
 Returns true if the string contains the given value.
 
bool contains (const char *val) const
 Returns true if the string contains the given value.
 
size_t count (const String &substr) const
 Counts non-overlapping occurrences of a substring.
 
String substr (size_t pos=0, size_t len=npos) const
 Returns a substring.
 
String mid (size_t pos, size_t count=npos) const
 Returns a substring starting at pos (alias for substr).
 
String left (size_t count) const
 Returns the first count characters.
 
String right (std::size_t count) const
 Returns the last count characters.
 
void clear ()
 Removes all characters from the string.
 
void resize (size_t val)
 Resizes the string to the given character count.
 
void erase (size_t pos, size_t count=1)
 Erases characters from the string.
 
void setCharAt (size_t idx, Char ch)
 Sets the character at the given index (promotes to Unicode if needed).
 
void insert (size_t pos, const String &s)
 Inserts a string at the given position (promotes to Unicode if needed).
 
Stringoperator= (const std::string &str)
 Assigns from a std::string (copy).
 
Stringoperator= (std::string &&str)
 Assigns from a std::string (move).
 
Stringoperator= (const char *str)
 Assigns from a C string.
 
Stringoperator+= (const String &val)
 Appends a String to this string (promotes to Unicode if needed).
 
Stringoperator+= (const std::string &val)
 Appends a String to this string (promotes to Unicode if needed).
 
Stringoperator+= (const char *val)
 Appends a String to this string (promotes to Unicode if needed).
 
Stringoperator+= (char val)
 Appends a String to this string (promotes to Unicode if needed).
 
String operator+ (const String &val) const
 Returns the concatenation of this string and val.
 
String operator+ (const std::string &val) const
 Returns the concatenation of this string and val.
 
String operator+ (const char *val) const
 Returns the concatenation of this string and val.
 
String operator+ (char val) const
 Returns the concatenation of this string and val.
 
bool operator== (const String &val) const
 Equality comparison with another String.
 
bool operator== (const char *val) const
 Equality comparison with another String.
 
bool operator== (char val) const
 Equality comparison with another String.
 
bool operator!= (const String &val) const
 Inequality comparison.
 
bool operator!= (const char *val) const
 Inequality comparison.
 
bool operator!= (char val) const
 Inequality comparison.
 
String toUpper () const
 Returns an uppercase copy of this string.
 
String toLower () const
 Returns a lowercase copy of this string.
 
String trim () const
 Returns a copy with leading and trailing whitespace removed.
 
bool startsWith (const String &prefix) const
 Returns true if the string starts with the given prefix.
 
bool startsWith (char c) const
 Returns true if the string starts with the given character.
 
bool endsWith (const String &suffix) const
 Returns true if the string ends with the given suffix.
 
String reverse () const
 Returns a copy with characters in reverse order.
 
bool isNumeric () const
 Returns true if every character is a decimal digit.
 
String replace (const String &find, const String &replacement) const
 Returns a copy with all occurrences of find replaced by replacement.
 
int compareIgnoreCase (const String &other) const
 Case-insensitive comparison.
 
uint64_t hash () const
 Returns a 64-bit FNV-1a hash of this string's native data.
 
String toLatin1 () const
 Returns a Latin1 version of this string.
 
String toUnicode () const
 Returns a Unicode version of this string.
 
Stringarg (const String &str)
 Replaces the lowest-numbered N placeholder with the given string.
 
Stringarg (int8_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Replaces the lowest {N} token with the formatted numeric value.
 
Stringarg (uint8_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Replaces the lowest {N} token with the formatted numeric value.
 
Stringarg (int16_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Replaces the lowest {N} token with the formatted numeric value.
 
Stringarg (uint16_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Replaces the lowest {N} token with the formatted numeric value.
 
Stringarg (int32_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Replaces the lowest {N} token with the formatted numeric value.
 
Stringarg (uint32_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Replaces the lowest {N} token with the formatted numeric value.
 
Stringarg (int64_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Replaces the lowest {N} token with the formatted numeric value.
 
Stringarg (uint64_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Replaces the lowest {N} token with the formatted numeric value.
 
template<typename OutputType >
OutputType to (Error *err=nullptr) const
 Converts the string to a value of type OutputType.
 
bool toBool (Error *err=nullptr) const
 Converts the string to a boolean.
 
int toInt (Error *err=nullptr) const
 Converts the string to an integer.
 
unsigned int toUInt (Error *err=nullptr) const
 Converts the string to an unsigned integer.
 
double toDouble (Error *err=nullptr) const
 Converts the string to a double.
 
int64_t parseNumberWords (Error *err=nullptr) const
 Parses English number words into an integer value.
 
StringList split (const std::string &delimiter) const
 Splits the string by a delimiter.
 

Static Public Member Functions

static String number (int8_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Converts a numeric value to its String representation.
 
static String number (uint8_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Converts a numeric value to its String representation.
 
static String number (int16_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Converts a numeric value to its String representation.
 
static String number (uint16_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Converts a numeric value to its String representation.
 
static String number (int32_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Converts a numeric value to its String representation.
 
static String number (uint32_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Converts a numeric value to its String representation.
 
static String number (int64_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Converts a numeric value to its String representation.
 
static String number (uint64_t value, int base=10, int padding=0, char padchar=' ', bool addPrefix=false)
 Converts a numeric value to its String representation.
 
static String number (bool value)
 Returns "true" or "false" for a boolean value.
 
static String number (float value, int precision=9)
 Converts a float to its string representation.
 
static String number (double value, int precision=9)
 Converts a float to its string representation.
 
template<typename T >
static String dec (const T &val, int padding=0, char padchar=' ')
 Formats a value as a decimal string with optional padding.
 
template<typename T >
static String hex (const T &val, int padding=0, bool addPrefix=true)
 Formats a value as a hexadecimal string.
 
template<typename T >
static String bin (const T &val, int digits=32, bool addPrefix=true)
 Formats a value as a binary string.
 
static String sprintf (const char *fmt,...)
 Creates a formatted string using printf-style syntax.
 
static String fromUtf8 (const char *data, size_t len)
 Creates a String by decoding UTF-8 data.
 
static String fromLiteralData (StringData *data)
 Wraps a static literal StringData without copying.
 

Static Public Attributes

static constexpr size_t npos = StringData::npos
 Sentinel value indicating "not found".
 
static constexpr const charWhitespaceChars = " \t\n\r\f\v"
 Characters considered whitespace by trim().
 

Friends

bool operator< (const String &lhs, const String &rhs)
 Less-than comparison (lexicographic on the encoded bytes).
 
bool operator<= (const String &lhs, const String &rhs)
 Less-than-or-equal comparison.
 
bool operator> (const String &lhs, const String &rhs)
 Greater-than comparison.
 
bool operator>= (const String &lhs, const String &rhs)
 Greater-than-or-equal comparison.
 

Detailed Description

Encoding-aware string class with copy-on-write semantics.

String is a lightweight handle wrapping a SharedPtr<StringData>. Copy is a refcount increment; mutation triggers COW. Latin1 is the fast path (byte == character). Unicode strings store decoded codepoints for O(1) indexed access.

Member Enumeration Documentation

◆ Encoding

String encoding.

Enumerator
Latin1 

One byte per character, ISO-8859-1.

Unicode 

Decoded codepoints, O(1) indexed access.

Constructor & Destructor Documentation

◆ String() [1/5]

String::String ( const char str)
inline

Constructs from a null-terminated C string.

Parameters
strThe C string (null treated as empty).

◆ String() [2/5]

String::String ( const char str,
size_t  len 
)
inline

Constructs from a character buffer with explicit length.

Parameters
strPointer to character data.
lenNumber of bytes.

◆ String() [3/5]

String::String ( size_t  ct,
char  c 
)
inline

Constructs a string of repeated characters.

Parameters
ctNumber of characters.
cCharacter to repeat.

◆ String() [4/5]

String::String ( const std::string &  str)
inline

Constructs from a std::string (copy).

Parameters
strThe source string.

◆ String() [5/5]

String::String ( std::string &&  str)
inline

Constructs from a std::string (move).

Parameters
strThe source string to move from.

Member Function Documentation

◆ arg()

String & String::arg ( const String str)

Replaces the lowest-numbered N placeholder with the given string.

Parameters
strThe replacement text.
Returns
Reference to this string.

◆ bin()

template<typename T >
static String String::bin ( const T val,
int  digits = 32,
bool  addPrefix = true 
)
inlinestatic

Formats a value as a binary string.

Template Parameters
TValue type (must support bitwise operations).
Parameters
valThe value to format.
digitsNumber of binary digits to emit (default 32).
addPrefixIf true, prepends "0b".
Returns
The formatted binary string.

◆ byteAt()

uint8_t String::byteAt ( size_t  idx) const
inline

Returns the byte at the given index.

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

◆ cbegin()

ConstIterator String::cbegin ( ) const
inlinenoexcept

Returns a const character iterator to the first character.

◆ cend()

ConstIterator String::cend ( ) const
inlinenoexcept

Returns a const character iterator past the last character.

◆ charAt()

Char String::charAt ( size_t  idx) const
inline

Returns the character at the given index.

Parameters
idxZero-based character index.
Returns
The character.

◆ compareIgnoreCase()

int String::compareIgnoreCase ( const String other) const
inline

Case-insensitive comparison.

Returns
Negative if *this < other, 0 if equal, positive if *this > other.

◆ contains() [1/4]

bool String::contains ( char  val) const
inline

Returns true if the string contains the given value.

Parameters
valThe value to search for.
Returns
True if found.

◆ contains() [2/4]

bool String::contains ( Char  val) const
inline

Returns true if the string contains the given value.

Parameters
valThe value to search for.
Returns
True if found.

◆ contains() [3/4]

bool String::contains ( const char val) const
inline

Returns true if the string contains the given value.

Parameters
valThe value to search for.
Returns
True if found.

◆ contains() [4/4]

bool String::contains ( const String val) const
inline

Returns true if the string contains the given value.

Parameters
valThe value to search for.
Returns
True if found.

◆ count()

size_t String::count ( const String substr) const
inline

Counts non-overlapping occurrences of a substring.

Parameters
substrThe substring to count.
Returns
Number of occurrences.

◆ dec()

template<typename T >
static String String::dec ( const T val,
int  padding = 0,
char  padchar = ' ' 
)
inlinestatic

Formats a value as a decimal string with optional padding.

Template Parameters
TInteger or arithmetic type.
Parameters
valThe value to format.
paddingMinimum field width.
padcharPadding character (default: space).
Returns
The formatted string.

◆ endsWith()

bool String::endsWith ( const String suffix) const
inline

Returns true if the string ends with the given suffix.

Parameters
suffixThe suffix to test.
Returns
True if this string ends with suffix.

◆ erase()

void String::erase ( size_t  pos,
size_t  count = 1 
)
inline

Erases characters from the string.

Parameters
posStarting character index.
countNumber of characters to erase (default 1).

◆ find() [1/4]

size_t String::find ( char  val,
size_t  from = 0 
) const
inline

Finds the first occurrence of a character.

Parameters
valThe character to find.
fromStarting character index (default 0).
Returns
Character index of the match, or npos if not found.

◆ find() [2/4]

size_t String::find ( Char  val,
size_t  from = 0 
) const
inline

Finds the first occurrence of a character.

Parameters
valThe character to find.
fromStarting character index (default 0).
Returns
Character index of the match, or npos if not found.

◆ find() [3/4]

size_t String::find ( const char val,
size_t  from = 0 
) const
inline

Finds the first occurrence of a character.

Parameters
valThe character to find.
fromStarting character index (default 0).
Returns
Character index of the match, or npos if not found.

◆ find() [4/4]

size_t String::find ( const String val,
size_t  from = 0 
) const
inline

Finds the first occurrence of a character.

Parameters
valThe character to find.
fromStarting character index (default 0).
Returns
Character index of the match, or npos if not found.

◆ fromLiteralData()

static String String::fromLiteralData ( StringData data)
inlinestatic

Wraps a static literal StringData without copying.

Used by PROMEKI_STRING. The literal data has an immortal refcount so it is never freed. Works with both StringLiteralData (Latin1) and StringUnicodeLiteralData.

◆ fromUtf8()

static String String::fromUtf8 ( const char data,
size_t  len 
)
inlinestatic

Creates a String by decoding UTF-8 data.

Parameters
dataPointer to UTF-8 bytes.
lenNumber of bytes.
Returns
A Unicode-encoded String.

◆ hash()

uint64_t String::hash ( ) const
inline

Returns a 64-bit FNV-1a hash of this string's native data.

Each StringData backend hashes its native storage directly, avoiding unnecessary encoding conversions.

◆ hex()

template<typename T >
static String String::hex ( const T val,
int  padding = 0,
bool  addPrefix = true 
)
inlinestatic

Formats a value as a hexadecimal string.

Template Parameters
TInteger type.
Parameters
valThe value to format.
paddingMinimum digit width (zero-padded).
addPrefixIf true, prepends "0x".
Returns
The formatted hex string.

◆ insert()

void String::insert ( size_t  pos,
const String s 
)
inline

Inserts a string at the given position (promotes to Unicode if needed).

Parameters
posZero-based character index.
sThe string to insert.

◆ left()

String String::left ( size_t  count) const
inline

Returns the first count characters.

Parameters
countNumber of characters to return.
Returns
The left substring.

◆ mid()

String String::mid ( size_t  pos,
size_t  count = npos 
) const
inline

Returns a substring starting at pos (alias for substr).

Parameters
posStarting character index.
countMaximum number of characters.
Returns
The substring.

◆ number() [1/11]

static String String::number ( bool  value)
inlinestatic

Returns "true" or "false" for a boolean value.

Parameters
valueThe boolean to convert.
Returns
"true" or "false".

◆ number() [2/11]

static String String::number ( double  value,
int  precision = 9 
)
static

Converts a float to its string representation.

Parameters
valueThe float to convert.
precisionNumber of decimal digits (default 9).
Returns
The formatted number string.

◆ number() [3/11]

static String String::number ( float  value,
int  precision = 9 
)
static

Converts a float to its string representation.

Parameters
valueThe float to convert.
precisionNumber of decimal digits (default 9).
Returns
The formatted number string.

◆ number() [4/11]

static String String::number ( int16_t  value,
int  base = 10,
int  padding = 0,
char  padchar = ' ',
bool  addPrefix = false 
)
static

Converts a numeric value to its String representation.

Parameters
valueThe value to convert.
baseNumeric base (2-36, default 10).
paddingMinimum width; padded with padchar.
padcharPadding character (default: space).
addPrefixIf true, adds a base prefix (e.g. "0x" for hex).
Returns
The formatted number string.

◆ number() [5/11]

static String String::number ( int32_t  value,
int  base = 10,
int  padding = 0,
char  padchar = ' ',
bool  addPrefix = false 
)
static

Converts a numeric value to its String representation.

Parameters
valueThe value to convert.
baseNumeric base (2-36, default 10).
paddingMinimum width; padded with padchar.
padcharPadding character (default: space).
addPrefixIf true, adds a base prefix (e.g. "0x" for hex).
Returns
The formatted number string.

◆ number() [6/11]

static String String::number ( int64_t  value,
int  base = 10,
int  padding = 0,
char  padchar = ' ',
bool  addPrefix = false 
)
static

Converts a numeric value to its String representation.

Parameters
valueThe value to convert.
baseNumeric base (2-36, default 10).
paddingMinimum width; padded with padchar.
padcharPadding character (default: space).
addPrefixIf true, adds a base prefix (e.g. "0x" for hex).
Returns
The formatted number string.

◆ number() [7/11]

static String String::number ( int8_t  value,
int  base = 10,
int  padding = 0,
char  padchar = ' ',
bool  addPrefix = false 
)
static

Converts a numeric value to its String representation.

Parameters
valueThe value to convert.
baseNumeric base (2-36, default 10).
paddingMinimum width; padded with padchar.
padcharPadding character (default: space).
addPrefixIf true, adds a base prefix (e.g. "0x" for hex).
Returns
The formatted number string.

◆ number() [8/11]

static String String::number ( uint16_t  value,
int  base = 10,
int  padding = 0,
char  padchar = ' ',
bool  addPrefix = false 
)
static

Converts a numeric value to its String representation.

Parameters
valueThe value to convert.
baseNumeric base (2-36, default 10).
paddingMinimum width; padded with padchar.
padcharPadding character (default: space).
addPrefixIf true, adds a base prefix (e.g. "0x" for hex).
Returns
The formatted number string.

◆ number() [9/11]

static String String::number ( uint32_t  value,
int  base = 10,
int  padding = 0,
char  padchar = ' ',
bool  addPrefix = false 
)
static

Converts a numeric value to its String representation.

Parameters
valueThe value to convert.
baseNumeric base (2-36, default 10).
paddingMinimum width; padded with padchar.
padcharPadding character (default: space).
addPrefixIf true, adds a base prefix (e.g. "0x" for hex).
Returns
The formatted number string.

◆ number() [10/11]

static String String::number ( uint64_t  value,
int  base = 10,
int  padding = 0,
char  padchar = ' ',
bool  addPrefix = false 
)
static

Converts a numeric value to its String representation.

Parameters
valueThe value to convert.
baseNumeric base (2-36, default 10).
paddingMinimum width; padded with padchar.
padcharPadding character (default: space).
addPrefixIf true, adds a base prefix (e.g. "0x" for hex).
Returns
The formatted number string.

◆ number() [11/11]

static String String::number ( uint8_t  value,
int  base = 10,
int  padding = 0,
char  padchar = ' ',
bool  addPrefix = false 
)
static

Converts a numeric value to its String representation.

Parameters
valueThe value to convert.
baseNumeric base (2-36, default 10).
paddingMinimum width; padded with padchar.
padcharPadding character (default: space).
addPrefixIf true, adds a base prefix (e.g. "0x" for hex).
Returns
The formatted number string.

◆ operator!=() [1/2]

bool String::operator!= ( char  val) const
inline

Inequality comparison.

◆ operator!=() [2/2]

bool String::operator!= ( const char val) const
inline

Inequality comparison.

◆ operator+() [1/4]

String String::operator+ ( char  val) const
inline

Returns the concatenation of this string and val.

Parameters
valThe string to concatenate.
Returns
A new String containing both parts.

◆ operator+() [2/4]

String String::operator+ ( const char val) const
inline

Returns the concatenation of this string and val.

Parameters
valThe string to concatenate.
Returns
A new String containing both parts.

◆ operator+() [3/4]

String String::operator+ ( const std::string &  val) const
inline

Returns the concatenation of this string and val.

Parameters
valThe string to concatenate.
Returns
A new String containing both parts.

◆ operator+() [4/4]

String String::operator+ ( const String val) const
inline

Returns the concatenation of this string and val.

Parameters
valThe string to concatenate.
Returns
A new String containing both parts.

◆ operator+=() [1/4]

String & String::operator+= ( char  val)
inline

Appends a String to this string (promotes to Unicode if needed).

Parameters
valThe string to append.
Returns
Reference to this string.

◆ operator+=() [2/4]

String & String::operator+= ( const char val)
inline

Appends a String to this string (promotes to Unicode if needed).

Parameters
valThe string to append.
Returns
Reference to this string.

◆ operator+=() [3/4]

String & String::operator+= ( const std::string &  val)
inline

Appends a String to this string (promotes to Unicode if needed).

Parameters
valThe string to append.
Returns
Reference to this string.

◆ operator+=() [4/4]

String & String::operator+= ( const String val)
inline

Appends a String to this string (promotes to Unicode if needed).

Parameters
valThe string to append.
Returns
Reference to this string.

◆ operator==() [1/3]

bool String::operator== ( char  val) const
inline

Equality comparison with another String.

Parameters
valThe string to compare with.
Returns
True if both strings have identical characters.

◆ operator==() [2/3]

bool String::operator== ( const char val) const
inline

Equality comparison with another String.

Parameters
valThe string to compare with.
Returns
True if both strings have identical characters.

◆ operator==() [3/3]

bool String::operator== ( const String val) const
inline

Equality comparison with another String.

Parameters
valThe string to compare with.
Returns
True if both strings have identical characters.

◆ parseNumberWords()

int64_t String::parseNumberWords ( Error err = nullptr) const

Parses English number words into an integer value.

Parameters
errOptional error output.
Returns
The parsed value (e.g. "twenty three" returns 23).

◆ resize()

void String::resize ( size_t  val)
inline

Resizes the string to the given character count.

Parameters
valNew character count.

◆ rfind() [1/4]

size_t String::rfind ( char  val,
size_t  from = npos 
) const
inline

Finds the last occurrence of a character.

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

◆ rfind() [2/4]

size_t String::rfind ( Char  val,
size_t  from = npos 
) const
inline

Finds the last occurrence of a character.

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

◆ rfind() [3/4]

size_t String::rfind ( const char val,
size_t  from = npos 
) const
inline

Finds the last occurrence of a character.

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

◆ rfind() [4/4]

size_t String::rfind ( const String val,
size_t  from = npos 
) const
inline

Finds the last occurrence of a character.

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

◆ right()

String String::right ( std::size_t  count) const
inline

Returns the last count characters.

Parameters
countNumber of characters to return.
Returns
The right substring.

◆ setCharAt()

void String::setCharAt ( size_t  idx,
Char  ch 
)
inline

Sets the character at the given index (promotes to Unicode if needed).

Parameters
idxZero-based character index.
chThe replacement character.

◆ split()

StringList String::split ( const std::string &  delimiter) const

Splits the string by a delimiter.

Parameters
delimiterThe delimiter string to split on.
Returns
A StringList containing the split parts.

◆ sprintf()

static String String::sprintf ( const char fmt,
  ... 
)
static

Creates a formatted string using printf-style syntax.

Parameters
fmtThe printf format string.
Returns
The formatted string.

◆ startsWith() [1/2]

bool String::startsWith ( char  c) const
inline

Returns true if the string starts with the given character.

Parameters
cThe character to test.

◆ startsWith() [2/2]

bool String::startsWith ( const String prefix) const
inline

Returns true if the string starts with the given prefix.

Parameters
prefixThe prefix to test.
Returns
True if this string begins with prefix.

◆ substr()

String String::substr ( size_t  pos = 0,
size_t  len = npos 
) const
inline

Returns a substring.

Parameters
posStarting character index (default 0).
lenMaximum number of characters (npos = rest of string).
Returns
The substring.

◆ to()

template<typename OutputType >
OutputType String::to ( Error err = nullptr) const
inline

Converts the string to a value of type OutputType.

Template Parameters
OutputTypeThe target type (int, long, double, float, etc).
Parameters
errOptional error output.
Returns
The converted value, or a default-constructed value on failure.

◆ toBool()

bool String::toBool ( Error err = nullptr) const

Converts the string to a boolean.

Parameters
errOptional error output.
Returns
The boolean value (recognizes "true"/"false" and "1"/"0").

◆ toDouble()

double String::toDouble ( Error err = nullptr) const

Converts the string to a double.

Parameters
errOptional error output.
Returns
The double value, or 0.0 on failure.

◆ toInt()

int String::toInt ( Error err = nullptr) const

Converts the string to an integer.

Parameters
errOptional error output.
Returns
The integer value, or 0 on failure.

◆ toLatin1()

String String::toLatin1 ( ) const
inline

Returns a Latin1 version of this string.

If already Latin1, returns a shallow copy (refcount increment). Otherwise converts, clamping codepoints above 0xFF to '?'.

◆ toUInt()

unsigned int String::toUInt ( Error err = nullptr) const

Converts the string to an unsigned integer.

Parameters
errOptional error output.
Returns
The unsigned integer value, or 0 on failure.

◆ toUnicode()

String String::toUnicode ( ) const
inline

Returns a Unicode version of this string.

If already Unicode, returns a shallow copy (refcount increment). Otherwise promotes Latin1 data to decoded codepoints.


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