Class String¶
Defined in File String.hpp
Class Documentation¶
-
class String¶
[source] Minimal string class used throughout the mutiny framework.
Provides just enough string functionality for assertion messages and internal bookkeeping without depending on the C++ standard library. The interface deliberately mirrors the subset of
std::stringthat the framework uses so that switching tostd::stringvia MUTINY_USE_STD_STRING requires no call-site changes.Public Functions
-
String(const char *value = "")¶
Construct from a NUL-terminated C string (default: empty).
-
String(const char *value, size_t len)¶
Construct from a pointer and an explicit byte count.
-
explicit String(StringView value)¶
Construct a copy from a StringView (explicit; allocates).
-
String(size_t count, char ch)¶
Construct a string of
countcopies of characterch.- Parameters:
count – Number of characters.
ch – Character to fill with.
-
String &operator+=(StringView sv)¶
Append the contents of a StringView.
-
inline char &operator[](size_t pos)¶
- Returns:
Reference to the character at position
pos.
-
inline const char &operator[](size_t pos) const¶
- Returns:
Const reference to the character at position
pos.
-
size_t find(char ch, size_t pos = 0) const¶
Find the first occurrence of
chat or afterpos.- Parameters:
ch – Character to search for.
pos – Starting position for the search.
- Returns:
Index of the first match, or
nposif not found.
-
size_t find(const char *s, size_t pos = 0) const¶
Find the first occurrence of the substring
sat or afterpos.- Parameters:
s – Substring to search for.
pos – Starting position for the search.
- Returns:
Index of the first match, or
nposif not found.
-
String substr(size_t begin_pos, size_t amount) const¶
- Returns:
Substring of at most
amountcharacters starting atbegin_pos.
-
const char *c_str() const¶
- Returns:
NUL-terminated pointer to the string’s character data.
-
const char *data() const¶
- Returns:
Read-only pointer to the character data.
-
size_t size() const¶
- Returns:
Number of characters (not counting the NUL terminator).
-
inline size_t capacity() const¶
- Returns:
Number of characters that fit without reallocation.
-
bool empty() const¶
- Returns:
true if the string has zero characters.
-
void reserve(size_t new_capacity)¶
Ensure at least
new_capacitycharacters fit without reallocation.
-
void resize(size_t new_size)¶
Resize the string to exactly
new_sizecharacters, padding with NUL bytes if growing.
Public Static Attributes
-
String(const char *value = "")¶