A template class for character strings. More...
#include <string.hpp>
Public Member Functions | |
string () noexcept | |
Default string constructor. | |
string (char chr) noexcept | |
Construct string from a single-byte character. | |
string (wchar_t chr) noexcept | |
Construct string from a wide character. | |
string (const uint32_t &chr) noexcept | |
Construct string from uint32_t. | |
string (const char *str) noexcept | |
Construct from a cstring of single-byte characters. | |
string (const char *str, size_t len) noexcept | |
Construct from a cstring of single-byte characters, with a known length. | |
string (const wchar_t *str) noexcept | |
Construct from a cstring of wide characters. | |
string (const wchar_t *str, size_t len) noexcept | |
Construct from a cstring of wide characters, with a known length. | |
string (const std::string &str) noexcept | |
Construct from a std::string. | |
template<typename INT , typename = typename std::enable_if<std::is_integral<INT>::value && !std::is_same<INT, char>::value && !std::is_same<INT, wchar_t>::value, INT>::type> | |
string (INT value, int base=10, int padSize=0) noexcept | |
Construct from an integer. | |
template<typename PTR , typename = typename std::enable_if<std::is_pointer<PTR>::value && !std::is_same<PTR, char *>::value && !std::is_same<PTR, wchar_t *>::value, PTR>::type> | |
string (PTR pointer) noexcept | |
Construct from a pointer. | |
template<typename FLT , typename = typename std::enable_if<std::is_floating_point<FLT>::value, FLT>::type> | |
string (FLT value, int base=10, int precision=0, bool scientific=true, int padSize=0) noexcept | |
Construct from floating-point. | |
template<typename T , typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> | |
string (const std::complex< T > &value, int base=10, int precision=0, bool scientific=true, int padSize=0) noexcept | |
Construct from complex number. | |
string (const string< ascii > &other) noexcept | |
Construct from an ASCII string. | |
string (const string< utf8 > &other) noexcept | |
Construct from a UTF-8 string. | |
string (const string< utf16 > &other) noexcept | |
Construct from a UTF16 string. | |
string (const string< utf32 > &other) noexcept | |
Construct from a UTF32 string. | |
string (string &&other) noexcept | |
Move constructor. | |
string & | operator= (string &&other) noexcept |
Move assignment operator. | |
~string () noexcept | |
Destructor. | |
void | increase (int charCount) noexcept |
Increase the space allocated for this string. | |
uint32_t | at (int index) const noexcept override |
Get the character at the given index. | |
size_t | size () const noexcept override |
Get the size of the string in memory. | |
int | length () const noexcept override |
Get the character count of the string. | |
int | chars () const noexcept |
Get the individual character count of the string. | |
const char * | cstring () const noexcept |
Get the single-byte cstring pointer. | |
const uint16_t * | nstring () const noexcept |
Get the two-byte cstring pointer. | |
const uint32_t * | wstring () const noexcept |
Get the four-byte cstring pointer. | |
constexpr encoding | format () const noexcept |
Get the encoding of this string. | |
long | integer (int base=10, uint32_t decimal='.') const noexcept |
Convert this string to an integer. | |
template<typename INT , typename = typename std::enable_if<std::is_integral<INT>::value, INT>::type> | |
operator INT () const noexcept | |
Convert this string to an integer. | |
double | floating (int base=10, uint32_t decimal='.') const noexcept |
Convert this string to a floating-point value. | |
operator double () const noexcept | |
Convert this string to a floating-point value. | |
operator float () const noexcept | |
Convert this string to a floating-point value. | |
constexpr | operator bool () const noexcept |
Check if this string contains at least one character. | |
std::complex< double > | complex (int base=10, uint32_t decimal='.') const noexcept |
Convert this string to a complex value. | |
int | count (const string &other) const noexcept |
Count the occurrences of a sub-string. | |
int | find (const string &other, int occurrence=1) const noexcept |
Find a specific occurrence of a sub-string. | |
int | found (const string &other, int occurrence=1) const noexcept |
Check if a specific occurrence of a sub-string exists. | |
int | findLast (const string &other, int occurrence=1) const noexcept |
Reverse-find a specific occurrence of a sub-string. | |
int | findAfter (const string &other, int index, int occurrence=1) const noexcept |
Find a specific occurrence of a sub-string. | |
int | findBefore (const string &other, int index, int occurrence=1) const noexcept |
Reverse-find a specific occurrence of a sub-string. | |
bool | foundAt (const string &other, int index) const noexcept |
Check if a sub-string is found at the given index. | |
bool | foundEndAt (const string &other, int index) const noexcept |
Check if a sub-string ends at the given index. | |
bool | beginsWith (const string &other) const noexcept |
Check if the string begins with a given sub-string. | |
bool | endsWith (const string &other) const noexcept |
Check if the string ends with a given sub-string. | |
bool | isInteger (int base=10) const noexcept |
Check if this string can convert to an integer. | |
bool | isFloating (int base=10, uint32_t decimal='.') const noexcept |
Check if this string can convert to a floating-point value. | |
bool | isComplex (int base=10, uint32_t decimal='.') const noexcept |
Check if this string can convert to a complex value. | |
int | type (int base=10, uint32_t decimal='.') const noexcept |
Determine the most basic type that this string can cast to. | |
string | substr (int index, int count) const noexcept |
Get a sub-string from this string. | |
string & | append (const string &other) noexcept |
Append another string to the end of this one. | |
string & | append (uint32_t chr) noexcept |
Append a single character to the end of the string. | |
string & | insert (const string &other, int index) noexcept |
Insert another string into this one. | |
string & | remove (const string &other, int occurrence=0) noexcept |
Remove occurrences of the given sub-string. | |
string & | remove (int index, int count) noexcept |
Remove a subset of the string. | |
string & | truncate (int index) noexcept |
Remove all characters from a given index to the end of the string. | |
string & | replace (const string &findStr, const string &replStr, int occurrence=0) noexcept |
Replace occurrences of the given sub-string. | |
string & | replace (int index, int count, const string &other) noexcept |
Replace a subset of the string. | |
string | padLeft (const string &other, int padSize) const noexcept |
Copy this string, left-padded given character count. | |
string & | padLeftIn (const string &other, int padSize) noexcept |
Left-pad this string up to a given character count. | |
string | padRight (const string &other, int padSize) const noexcept |
Copy this string, right-padded given character count. | |
string & | padRightIn (const string &other, int padSize) noexcept |
Right-pad this string up to a given character count. | |
string | repeat (int count) const noexcept |
Repeat this string a specific number of times. | |
string | trimLeft (const string &other="") const noexcept |
Copies this string and removes padding from the left side of the result. | |
string | trimRight (const string &other="") const noexcept |
Copies this string and removes padding from the right side of the result. | |
string & | trimLeftIn (const string &other="") noexcept |
Remove padding from the left side of this string. | |
string & | trimRightIn (const string &other="") noexcept |
Remove padding from the right side of this string. | |
string | trim (const string &other="") const noexcept |
Copies this string and removes padding from both sides of the result. | |
string & | trimIn (const string &other="") noexcept |
Remove padding from the both sides of this string. | |
void | clear () noexcept |
Reset to a null string. | |
string & | cutDuplicates (const string &other) noexcept |
Remove all sequential duplicates from this string. | |
string | upper () const noexcept |
Get an uppercase version of this string. | |
string | lower () const noexcept |
Get a lowercase version of this string. | |
string | camel () const noexcept |
Get a camelcase version of this string. | |
string & | toUpper () noexcept |
Convert all characters in the string to uppercase. | |
string & | toLower () noexcept |
Convert all characters in the string to lowercase. | |
string & | toCamel () noexcept |
Convert all characters in the string to camelcase. | |
string | filter (uint32_t first, uint32_t last, bool invert=false) const noexcept |
Filter out all characters not in the given range. | |
string | filter (const std::pair< uint32_t, uint32_t > &range, bool invert=false) const noexcept |
Filter out all characters not in the given range. | |
string | filter (const std::initializer_list< const std::pair< uint32_t, uint32_t > > &list, bool invert=false) const noexcept |
Filter out all characters not in the given range. | |
string | filter (const string &list, bool invert=false) const noexcept |
Filter out all characters not in the given string. | |
string | filter (std::function< bool(uint32_t)> lambda) const noexcept |
Filter out characters based on a function. | |
bool | contains (uint32_t first, uint32_t last, bool exclusive=false) const noexcept |
Check if this string contains any characters in the given range. | |
bool | contains (const std::pair< uint32_t, uint32_t > &range, bool exclusive=false) const noexcept |
Check if this string contains any characters in the given range. | |
bool | contains (const std::initializer_list< const std::pair< uint32_t, uint32_t > > &list, bool exclusive=false) const noexcept |
Check if this string contains any characters in the given ranges. | |
bool | contains (const string &list, bool exclusive=false) const noexcept |
Check if this string contains any of the characters in the given string. | |
string | cipher (const string &keys, const string &values) const noexcept |
Convert this string from one set of characters to another. | |
string | cipher (std::function< uint32_t(uint32_t)> lambda) const noexcept |
Convert this string from one set of characters to another. | |
string | concat (const string &other) const noexcept |
Concatenate two strings. | |
string | operator+ (const string &other) const noexcept |
Concatenate two strings. | |
string & | operator+= (const string &other) noexcept |
Append another string to the end of this one. | |
string & | operator= (const string &other) noexcept |
Assign the contents of this string. | |
bool | operator== (const string &other) const noexcept |
Equality comparison. | |
bool | operator!= (const string &other) const noexcept |
Inequality comparison. | |
bool | operator> (const string &other) const noexcept |
Greater-than comparison. | |
bool | operator>= (const string &other) const noexcept |
Greater-than or equal comparison. | |
bool | operator< (const string &other) const noexcept |
Less-than comparison. | |
bool | operator<= (const string &other) const noexcept |
Less-than or equal comparison. | |
string & | read (std::istream &stream, uint32_t delim=0) noexcept |
Read string data from a stream until the given delimiter is encountered. | |
string & | readln (std::istream &stream) noexcept |
Read string data from a stream until a newline is encountered. | |
string & | readall (std::istream &stream) noexcept |
Read an entire stream's contents into this string. | |
void | write (std::ostream &stream) const noexcept |
Write string data to a stream in that stream's encoding. | |
void | writeln (std::ostream &stream) const noexcept |
Write string data to a stream in its format, appending a newline. | |
stringIterator< E > | begin () const noexcept override |
Get an iterator for the beginning of the string. | |
stringIterator< E > | end () const noexcept override |
Get an iterator for the end of the string. | |
template<class archive > | |
std::string | save_minimal (archive &ar) const |
Serialization output. | |
template<class archive > | |
void | load_minimal (archive const &ar, std::string const &value) |
Serialization input. | |
std::string | str () const noexcept |
Convert to a std::string. | |
hash32 | hash () const noexcept |
Compute the CRC32 hash of this string. | |
![]() | |
virtual | ~sizable () noexcept |
Virtual destructor. | |
![]() | |
virtual | ~indexable () noexcept |
Virtual destructor. | |
virtual T | operator[] (int index) const |
Function to get the object at the given index. | |
![]() | |
virtual | ~iterable () noexcept |
Virtual destructor. | |
Static Public Member Functions | |
static string | words (long long value, bool ordinal=false) noexcept |
Generate an English representation of a given number. | |
static string | ordinal (long long value) noexcept |
Get the ordinal suffix of a given integer. | |
static string | precision (double value, int precision, bool forcePrecision=false) noexcept |
Create a string from a number with a fixed number of decimal places. | |
static string | numberFormat (double value, int precision=0, bool forcePrecision=false, char decimal='.', char thousands=',') noexcept |
Create a string from a number with thousands separators. | |
Friends | |
std::ostream & | operator<< (std::ostream &ostr, const z::core::string< E > &str) |
Stream output operator. | |
std::istream & | operator>> (std::istream &istr, z::core::string< E > &str) |
Stream input operator. | |
A template class for character strings.
This class focuses on how characters are encoded rather than character size. Possible encoding schemes are ASCII, UTF-8, UTF16, and UTF32.
When characters are input or output, they are converted to or from their encoding scheme to a single UTF32 character. Thus, the "default" character type is uint32_t
.
Note this class is compatible with standard library streams, but also has read(), readln(), write(), writeln() methods for interacting with core::stream objects (Useful if a specific encoding is strictly required).
To keep string types short, you may append _u32, _u16, _u8, or _asc after any literals. For example, here are a few different ways to construct a UTF32 encoded string:
The above will all be of type z::core::string<z::utf32>
|
explicitnoexcept |
Construct string from a single-byte character.
chr | Initializing character. |
Character is assumed to be compatible with this string's encoding.
|
explicitnoexcept |
Construct string from a wide character.
chr | Initializing character. |
Converts the given character to the appropriate encoding for this string.
|
noexcept |
Construct string from uint32_t.
chr | Initializing character. |
This constructor exists to allow a "default" string character to again be constructed into a string. Converts the given character to the appropriate encoding for this string.
|
noexcept |
Construct from a cstring of single-byte characters.
str | Null-terminated cstring. |
All characters are assumed to be compatible with this string's encoding.
Construct from a cstring of single-byte characters, with a known length.
str | A cstring, which may or may not be null-terminated. |
len | The length of the string. |
All characters are assumed to be compatible with this string's encoding.
|
noexcept |
Construct from a cstring of wide characters.
str | Null-terminated cstring. |
Converts the characters in the given cstring to the appropriate encoding for this string.
|
noexcept |
Construct from a cstring of wide characters, with a known length.
str | A cstring, which may or may not be null-terminated. |
len | The length of the string. |
All characters are assumed to be compatible with this string's encoding.
|
inlinenoexcept |
Construct from a std::string.
str | The string to copy. |
All characters are assumed to be compatible with this string's encoding.
|
inlinenoexcept |
Construct from an integer.
value | An integer. |
base | The number's base. |
padSize | Number of characters to pad up to. |
Converts an integer to a string in the given base. If the character count is less than the pad size, zeroes are added to the left side until the character count equals the pad size. Valid base sizes are from 2 to 36, and anything else is assumed to be base 10. If the pad size is less than 1, no character padding is applied.
|
inlinenoexcept |
Construct from a pointer.
pointer | A pointer. |
Creates a string representation from a pointer, of the form 0xFFFFFFFF
. If Z_STR_POINTER_FORCE
is defined as true
, then the hex part of the string is padded up to Z_STR_POINTER_CHARS
characters (default is 8).
|
inlinenoexcept |
Construct from floating-point.
value | A floating-point number. |
base | The number's base. |
precision | The number of characters after the decimal point. |
scientific | Whether to use scientific notation. |
padSize | Number of characters to pad up to. |
Converts a floating-point number to a string in the given base. If the character count is less than the pad size, zeroes are added to the left side until the character count equals the pad size. Valid base sizes are from 2 to 36, and anything else is assumed to be base 10. If the pad size is less than 1, no character padding is applied. If the precision is 1 or greater, then exactly that many digits will show after the decimal point, otherwise up to Z_STR_FLOAT_PRECISION
digits will show (default is 6).
|
inlinenoexcept |
Construct from complex number.
value | A floating-point complex number. |
base | The number's base. |
precision | The number of characters after the decimal point. |
scientific | Whether to use scientific notation. |
padSize | Number of characters to pad up to. |
Converts a floating-point complex number to a string in the given base. This string will look like X+Yi
, X-Yi
, -X+Yi
, or -X-Yi
. Valid base sizes are from 2 to 36, and anything else is assumed to be base 10. If the precision is 1 or greater, then exactly that many digits will show after the decimal point, otherwise up to Z_STR_FLOAT_PRECISION
digits will show (default is 6).
|
noexcept |
Construct from an ASCII string.
other | An ASCII encoded string. |
Copies over characters from the given string, converting them to the appropriate encoding scheme for this string.
|
noexcept |
Construct from a UTF-8 string.
other | A UTF-8 encoded string. |
Copies over characters from the given string, converting them to the appropriate encoding scheme for this string.
|
noexcept |
Construct from a UTF16 string.
other | A UTF16 encoded string. |
Copies over characters from the given string, converting them to the appropriate encoding scheme for this string.
|
noexcept |
Construct from a UTF32 string.
other | A UTF32 encoded string. |
Copies over characters from the given string, converting them to the appropriate encoding scheme for this string.
|
inlinenoexcept |
Move constructor.
Moves a string of the same encoding. Just does a mem copy.
other | The string to move. |
|
inlinenoexcept |
Append another string to the end of this one.
other | The string to append. |
|
noexcept |
Append a single character to the end of the string.
Use this method if you need to append raw characters (i.e. they're coming from a stream), as it is more efficient than first casting the character to a string and appending that way.
chr | The character to append, in UTF32 format. |
|
overridevirtualnoexcept |
Get the character at the given index.
index | The index of the character to get. |
If the index is greater than the character count, the null character is returned. For UTF-8 strings, if the chracter at the given index is part of a multibyte sequence, that sequence is converted to UTF32 and returned.
Implements z::core::indexable< T >.
|
inlineoverridevirtualnoexcept |
Get an iterator for the beginning of the string.
This member function should not be used directly. It is meant for C++11's range-based for loop syntax.
Implements z::core::iterable< ITER >.
|
inlinenoexcept |
Check if the string begins with a given sub-string.
other | The sub-string to check for. |
|
inlinenoexcept |
Get a camelcase version of this string.
|
noexcept |
Get the individual character count of the string.
For UTF-8 strings, multibyte sequences are counted as a single character.
|
noexcept |
Convert this string from one set of characters to another.
For each character in this string, if it's one of the keys, it will be replaced with the respective value. For example zstring("message").cipher("aegms","12345")
will output 4255132
.
keys | The characters to find and convert. |
values | The characters to convert to. |
|
noexcept |
Convert this string from one set of characters to another.
For each character in this string, it is passed to a function to mutate it. The function is expected to be of the form uint32_t func(uint32_t ch) {...}
. For example zstring("message").cipher([](auto a){ return a + 1; })
will output nfttbhf
.
lambda | An arbitrary function that converts the characters in this string. |
|
noexcept |
Convert this string to a complex value.
base | The base this string is being interpreted as. |
decimal | The character used to denote the radix (decimal place). |
|
inlinenoexcept |
Concatenate two strings.
other | The string to append. |
Appends the given string to the end of this string's characters and returns the result. This string is not modified.
|
noexcept |
Check if this string contains any characters in the given ranges.
example: this->contains({{'A', 'Z'}, {'a', 'z'}, {'0', '9'}}) will return true if this string contains an alphanumeric character.
list | A list of std::pair objects denoting all valid character ranges. |
exclusive | Return false if this string contains any characters NOT in any of the given ranges. |
exclusive
flag is set, whether it contains ONLY characters in the given ranges.
|
inlinenoexcept |
Check if this string contains any characters in the given range.
example: this->contains({'A', 'Z'}) will return true if this string contains a character in the range A -> Z, inclusive.
range | A std::pair denoting the character range. |
exclusive | Return false if this string contains any characters NOT in the given string. |
exclusive
flag is set, whether it contains ONLY characters in the given range.
|
noexcept |
Check if this string contains any of the characters in the given string.
example: this->contains("aeiouyAEIOUY") will return true if this contains a vowel.
list | A string indicating the list of valid characters. |
exclusive | Return false if this string contains any characters NOT in the given string. |
exclusive
flag is set, whether it contains ONLY characters in the given string.
|
inlinenoexcept |
Check if this string contains any characters in the given range.
example: this->contains('A', 'Z') will return true if this string contains a character in the range A -> Z, inclusive.
first | The first character in the range. |
last | The last character in the range. |
exclusive | Return false if this string contains any characters NOT in the given string. |
exclusive
flag is set, whether it contains ONLY characters in the given range.
|
noexcept |
Count the occurrences of a sub-string.
other | The sub-string to search for. |
|
noexcept |
Get the single-byte cstring pointer.
NULL
otherwise.
|
noexcept |
Remove all sequential duplicates from this string.
other | The string to remove duplicates of. |
Removes all contiguous repetitions of the given sub-string, leaving one instance of the sub-string where the group was.
|
inlineoverridevirtualnoexcept |
Get an iterator for the end of the string.
This member function should not be used directly. It is meant for C++11's range-based for loop syntax.
Implements z::core::iterable< ITER >.
|
inlinenoexcept |
Check if the string ends with a given sub-string.
other | The sub-string to check for. |
|
noexcept |
Filter out all characters not in the given range.
example: this->filter({{'A', 'Z'}, {'a', 'z'}, {'0', '9'}}) will remove all characters that are not alphanumeric.
list | A list of std::pair objects denoting all valid character ranges. |
invert | Invert the selection, that is, remove all characters that ARE in the given range. |
|
inlinenoexcept |
Filter out all characters not in the given range.
example: this->filter({'A', 'Z'}) will remove all characters not in the range A -> Z, inclusive.
range | A std::pair denoting the character range. |
invert | Invert the selection, that is, remove all characters that ARE in the given range. |
|
noexcept |
Filter out all characters not in the given string.
example: this->filter("aeiouyAEIOUY") will remove all non-vowel characters.
list | A string indicating the list of valid characters. |
invert | Invert the selection, that is, remove all characters that ARE in the given range. |
|
noexcept |
Filter out characters based on a function.
example: my_string.filter(z::core::isAlphaNumeric)
will remove all characters that are not alphanumeric.
lambda | The function used to determine whether to keep a given character. If this function returns true, the character stays in the string. If false, the character is removed. |
|
inlinenoexcept |
Filter out all characters not in the given range.
example: this->filter('A', 'Z') will remove all characters not in the range A -> Z, inclusive.
first | The first character in the range. |
last | The last character in the range. |
invert | Invert the selection, that is, remove all characters that ARE in the given range. |
|
inlinenoexcept |
Find a specific occurrence of a sub-string.
other | The sub-string to search for. |
occurrence | The occurrence of the sub-string to find. |
Attempts to find given occurrence of the sub-string starting at the beginning of the string. Note that the occurrence starts at 1. If the occurrence is less than 1, then -1 is returned.
|
inlinenoexcept |
Find a specific occurrence of a sub-string.
other | The sub-string to search for. |
index | The index to start at. |
occurrence | The occurrence of the sub-string to find. |
Attempts to find given occurrence of the sub-string, searching forward starting at the given index. Note that the occurrence starts at 1. If the occurrence is less than 1, then -1 is returned.
|
noexcept |
Reverse-find a specific occurrence of a sub-string.
other | The sub-string to search for. |
index | The index to start at. |
occurrence | The occurrence of the sub-string to find. |
Attempts to find given occurrence of the sub-string, searching backward starting at the given index. Note that the occurrence starts at 1. If the occurrence is less than 1, then -1 is returned.
|
inlinenoexcept |
Reverse-find a specific occurrence of a sub-string.
other | The sub-string to search for. |
occurrence | The occurrence of the sub-string to find. |
Attempts to find given occurrence of the sub-string starting at the end of the string. Note that the occurrence starts at 1. If the occurrence is less than 1, then -1 is returned.
|
noexcept |
Convert this string to a floating-point value.
base | The base this string is being interpreted as. |
decimal | The character used to denote the radix (decimal place). |
|
inlineconstexprnoexcept |
Get the encoding of this string.
|
inlinenoexcept |
Check if a specific occurrence of a sub-string exists.
other | The sub-string to search for. |
occurrence | The occurrence of the sub-string to find. |
Attempts to find given occurrence of the sub-string starting at the beginning of the string. Note that the occurrence starts at 1. If the occurrence is less than 1, then false is returned.
|
noexcept |
Check if a sub-string is found at the given index.
other | The sub-string to check for. |
index | The index in the string to look at. |
|
noexcept |
Check if a sub-string ends at the given index.
other | The sub-string to check for. |
index | The index in the string to look at. |
|
noexcept |
|
noexcept |
Increase the space allocated for this string.
If this string currently has fewer than max_chars allocated, enough space is reallocated to hold at least that many characters. Note that strings follow an approximate 1.5x growth pattern.
charCount | The minimum number of characters this string should be able to contain before reallocating. |
|
noexcept |
Insert another string into this one.
other | The string to insert. |
index | The index to insert before. |
Inserts the given string before the given index. So, for B = "abc"
and A = "xyz"
, A.insert(B,0)
would give "abcxyz"
, A.insert(B,1)
would give "xabcyz"
, etc.
|
noexcept |
Convert this string to an integer.
base | The base this string is being interpreted as. |
decimal | The character used to denote the radix (decimal place). |
|
inlinenoexcept |
Check if this string can convert to a complex value.
base | The base this string is being interpreted as. |
decimal | The character that is used as a decimal separator. |
Valid strings must follow the form X+Yi
or Xi+Y
, where X
and Y
are floating-point values. X
may optionally have a +
or -
preceding it, and Y
may be preceded by a -
instead of a +
.
|
inlinenoexcept |
Check if this string can convert to a floating-point value.
base | The base this string is being interpreted as. |
decimal | The character that is used as a decimal separator. |
Valid strings may optionally begin with a +
or -
, and contain only one period (decimal point). The number may also have an exponent in the same base, in the form XXeY
, where the exponent Y
may optionally begin with a +
or -
. Unlike the main number, this exponent must be an integer.
|
inlinenoexcept |
Check if this string can convert to an integer.
base | The base this string is being interpreted as. |
Valid strings may contain only numeric characters in the given base, and may optionally begin with a +
or -
.
|
overridevirtualnoexcept |
Get the character count of the string.
For UTF-8 strings, multibyte sequences are counted as multiple characters.
Implements z::core::arrayLike< T, ITER >.
|
inline |
Serialization input.
ar | The input archive. |
value | The string to input from serial archive. |
|
inlinenoexcept |
Get a lowercase version of this string.
|
noexcept |
Get the two-byte cstring pointer.
NULL
otherwise.
|
staticnoexcept |
Create a string from a number with thousands separators.
value | The value to convert to a string. |
precision | The number of digits after the decimal point. |
forcePrecision | If true, always show the specified number of digits after the decimal point, even if they are zeroes. |
decimal | The character to use as a decimal separator. |
thousands | The character to use as a thousands separator. |
|
inlineexplicitconstexprnoexcept |
Check if this string contains at least one character.
length() > 0
, false otherwise.
|
inlineexplicitnoexcept |
Convert this string to a floating-point value.
|
inlineexplicitnoexcept |
Convert this string to a floating-point value.
|
inlineexplicitnoexcept |
Convert this string to an integer.
|
inlinenoexcept |
Inequality comparison.
other | The string to compare to. |
|
noexcept |
Concatenate two strings.
other | The string to append. |
Appends the given string to the end of this string's characters and returns the result. This string is not modified.
|
noexcept |
Append another string to the end of this one.
other | The string to append. |
|
noexcept |
Less-than comparison.
other | The string to compare to. |
|
inlinenoexcept |
Less-than or equal comparison.
other | The string to compare to. |
|
noexcept |
Assign the contents of this string.
other | The string to copy from. |
Copies all characters from the given string over to this string, replacing current data.
|
inlinenoexcept |
Move assignment operator.
Moves a string of the same encoding. Since this string has already been allocated data, we must first deallocate, then do a mem copy.
other | The string to move. |
|
noexcept |
Equality comparison.
other | The string to compare to. |
|
noexcept |
Greater-than comparison.
other | The string to compare to. |
|
inlinenoexcept |
Greater-than or equal comparison.
other | The string to compare to. |
|
staticnoexcept |
Get the ordinal suffix of a given integer.
This gives the suffix only. E.g. ordinal(1) -> "st", ordinal(3) -> "rd", ordinal(57) -> "th", etc.
value | The value get the ordinal suffix of. |
|
inlinenoexcept |
Copy this string, left-padded given character count.
other | The string to pad on the left of the string. |
padSize | the number of characters to pad up to. |
If the given string contains more than one character, then some of that string's characters may be cut off in the resultant string. If the pad size is equal or less than the current chracter count, then no padding will be added.
|
noexcept |
Left-pad this string up to a given character count.
other | The string to pad on the left of this string. |
padSize | the number of characters to pad up to. |
If the given string contains more than one character, then some of that string's characters may be cut off in the resultant string. If the pad size is equal or less than the current chracter count, then no padding will be added.
|
inlinenoexcept |
Copy this string, right-padded given character count.
other | The string to pad on the right of the string. |
padSize | the number of characters to pad up to. |
If the given string contains more than one character, then some of that string's characters may be cut off in the resultant string. If the pad size is equal or less than the current chracter count, then no padding will be added.
|
noexcept |
Right-pad this string up to a given character count.
other | The string to pad on the right of this string. |
padSize | the number of characters to pad up to. |
If the given string contains more than one character, then some of that string's characters may be cut off in the resultant string. If the pad size is equal or less than the current chracter count, then no padding will be added.
|
inlinestaticnoexcept |
Create a string from a number with a fixed number of decimal places.
value | The value to convert to a string. |
precision | The number of digits after the decimal point. |
forcePrecision | If true, always show the specified number of digits after the decimal point, even if they are zeroes. |
|
noexcept |
Read string data from a stream until the given delimiter is encountered.
Reads until the delimiting character is encountered, or the stream is exhausted. If the delimiter is 0 or not given, the delimiter is assumed to be any white space character. Leading delimiter characters are skipped over until a non-delimiter character is encountered or the stream is exhausted. Any data this string contains is wiped when this function is called.
stream | The stream to read from. |
delim | The delimiter to read until. |
|
noexcept |
Read an entire stream's contents into this string.
Reads until the stream is exhausted. Any data this string contains is wiped when this function is called.
stream | The stream to read from. |
|
noexcept |
Read string data from a stream until a newline is encountered.
Reads until a newline is encountered (either \r\n
or \n
), or the stream is exhausted. Leading newlines are not skipped, so as to allow for empty lines. Any data this string contains is wiped when this function is called.
stream | The stream to read from. |
|
noexcept |
Remove occurrences of the given sub-string.
other | The sub-string to remove. |
occurrence | The occurrence to remove. |
If the occurrence is 0, all occurrences of the sub-string are removed. If the occurrence is negative, then none are removed. Otherwise, only the specified occurrence of the sub-string is removed from the main string, starting from the beginning.
Remove a subset of the string.
index | The starting index. |
count | The number of characters to remove. |
If count is 0, no characters are removed. If count is negative, characters are removed in reverse order.
|
inlinenoexcept |
Repeat this string a specific number of times.
count | the number of times to repeat this string. |
|
noexcept |
Replace occurrences of the given sub-string.
findStr | The sub-string to replace. |
replStr | The string to replace the sub-string with. |
occurrence | The occurrence to remove. |
If the occurrence is 0, all occurrences of the sub-string are replaced. If the occurrence is negative, then none are replaced. Otherwise, only the specified occurrence of the sub-string is replaced, starting from the beginning of this string.
|
noexcept |
Replace a subset of the string.
index | The starting index. |
count | The number of characters to remove. |
other | The string to replace the subset with. |
If count is 0, no characters are replaced. Characters are replaced in forward-order whether count is positive or negative.
|
inline |
Serialization output.
ar | The output archive. |
|
overridevirtualnoexcept |
Get the size of the string in memory.
Implements z::core::sizable.
|
inlinenoexcept |
Convert to a std::string.
|
noexcept |
Get a sub-string from this string.
index | The sub-string starting index. |
count | The number of characters in the sub-string. |
If count is 0, a null string is returned. If count is negative, characters are added in reverse order.
e.g. for string str = "example"
, str.substr(2,3)
will give "amp"
, and str.substr(5,-3)
will give "pma"
.
|
noexcept |
Convert all characters in the string to camelcase.
|
noexcept |
Convert all characters in the string to lowercase.
|
noexcept |
Convert all characters in the string to uppercase.
|
inlinenoexcept |
Copies this string and removes padding from both sides of the result.
other | The pad string to remove. |
Removes all occurrences of the given pad string from the left and right sides of this string.
|
inlinenoexcept |
Remove padding from the both sides of this string.
other | The pad string to remove. |
Removes all occurrences of the given pad string from the left and right sides of this string.
|
inlinenoexcept |
Copies this string and removes padding from the left side of the result.
other | The pad string to remove. |
Removes all occurrences of the given pad string from the left side of this string.
|
inlinenoexcept |
Remove padding from the left side of this string.
other | The pad string to remove. |
Removes all occurrences of the given pad string from the left side of this string.
|
inlinenoexcept |
Copies this string and removes padding from the right side of the result.
other | The pad string to remove. |
Removes all occurrences of the given pad string from the right side of this string.
|
inlinenoexcept |
Remove padding from the right side of this string.
other | The pad string to remove. |
Removes all occurrences of the given pad string from the right side of this string.
|
noexcept |
Remove all characters from a given index to the end of the string.
This function is faster than remove() at truncating string contents, because no actual data copying takes place. The character at the given index is simply set to the null char \0.
index | The index of the first character to remove. |
|
noexcept |
Determine the most basic type that this string can cast to.
base | The base that numbers are assumed to be in. |
decimal | The character that is used as a decimal separator. |
|
inlinenoexcept |
Get an uppercase version of this string.
|
staticnoexcept |
Generate an English representation of a given number.
value | The number to represent in English. |
ordinal | If true, output with ordinal suffix. |
|
inlinenoexcept |
Write string data to a stream in that stream's encoding.
stream | The stream to write to. |
|
inlinenoexcept |
Write string data to a stream in its format, appending a newline.
Actual characters in the newline depends on operating system (usually \n
, \r\n
on Windows).
stream | The stream to write to. |
|
noexcept |
Get the four-byte cstring pointer.
NULL
otherwise.
|
friend |
Stream output operator.
ostr | The output stream. |
str | The string to write to the stream. |
|
friend |
Stream input operator.
istr | The input stream. |
str | The string to read from the stream. |