libzed 1.9.9
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
z::core::string< E > Class Template Reference

A template class for character strings. More...

#include <string.hpp>

Inheritance diagram for z::core::string< E >:
z::core::sizable z::core::arrayLike< T, ITER > z::core::indexable< T > z::core::iterable< ITER >

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.
 
stringoperator= (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 charcstring () const noexcept
 Get the single-byte cstring pointer.
 
const uint16_tnstring () const noexcept
 Get the two-byte cstring pointer.
 
const uint32_twstring () 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< doublecomplex (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.
 
stringappend (const string &other) noexcept
 Append another string to the end of this one.
 
stringappend (uint32_t chr) noexcept
 Append a single character to the end of the string.
 
stringinsert (const string &other, int index) noexcept
 Insert another string into this one.
 
stringremove (const string &other, int occurrence=0) noexcept
 Remove occurrences of the given sub-string.
 
stringremove (int index, int count) noexcept
 Remove a subset of the string.
 
stringtruncate (int index) noexcept
 Remove all characters from a given index to the end of the string.
 
stringreplace (const string &findStr, const string &replStr, int occurrence=0) noexcept
 Replace occurrences of the given sub-string.
 
stringreplace (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.
 
stringpadLeftIn (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.
 
stringpadRightIn (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.
 
stringtrimLeftIn (const string &other="") noexcept
 Remove padding from the left side of this string.
 
stringtrimRightIn (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.
 
stringtrimIn (const string &other="") noexcept
 Remove padding from the both sides of this string.
 
void clear () noexcept
 Reset to a null string.
 
stringcutDuplicates (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.
 
stringtoUpper () noexcept
 Convert all characters in the string to uppercase.
 
stringtoLower () noexcept
 Convert all characters in the string to lowercase.
 
stringtoCamel () 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.
 
stringoperator+= (const string &other) noexcept
 Append another string to the end of this one.
 
stringoperator= (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.
 
stringread (std::istream &stream, uint32_t delim=0) noexcept
 Read string data from a stream until the given delimiter is encountered.
 
stringreadln (std::istream &stream) noexcept
 Read string data from a stream until a newline is encountered.
 
stringreadall (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< Ebegin () const noexcept override
 Get an iterator for the beginning of the string.
 
stringIterator< Eend () 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.
 
- Public Member Functions inherited from z::core::sizable
virtual ~sizable () noexcept
 Virtual destructor.
 
- Public Member Functions inherited from z::core::indexable< T >
virtual ~indexable () noexcept
 Virtual destructor.
 
virtual T operator[] (int index) const
 Function to get the object at the given index.
 
- Public Member Functions inherited from z::core::iterable< ITER >
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.
 

Detailed Description

template<encoding E = utf8>
class z::core::string< E >

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:

auto str1 = "hello world"_u32;
auto str2 = L"hello too!"_u32;
auto str3 = 'X'_u32;
auto str4 = 1234_u32;
A wrapper for std::vector.
Definition array.hpp:72

The above will all be of type z::core::string<z::utf32>

Note
Allocated memory is increased as needed with approximate 1.5x growth, and is not decreased on subsequent data changes, except in the case where data is copied over to a different string.
See also
encoding.h
zstr.h
Examples
chainGenerators.cpp, file.cpp, generator.cpp, hash32.cpp, lines.cpp, numberwang.cpp, regexConsole.cpp, and rot13.cpp.

Constructor & Destructor Documentation

◆ string() [1/17]

template<encoding E = utf8>
z::core::string< E >::string ( char  chr)
explicitnoexcept

Construct string from a single-byte character.

Parameters
chrInitializing character.

Character is assumed to be compatible with this string's encoding.

◆ string() [2/17]

template<encoding E = utf8>
z::core::string< E >::string ( wchar_t  chr)
explicitnoexcept

Construct string from a wide character.

Parameters
chrInitializing character.

Converts the given character to the appropriate encoding for this string.

◆ string() [3/17]

template<encoding E = utf8>
z::core::string< E >::string ( const uint32_t chr)
noexcept

Construct string from uint32_t.

Parameters
chrInitializing 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.

◆ string() [4/17]

template<encoding E = utf8>
z::core::string< E >::string ( const char str)
noexcept

Construct from a cstring of single-byte characters.

Parameters
strNull-terminated cstring.

All characters are assumed to be compatible with this string's encoding.

◆ string() [5/17]

template<encoding E = utf8>
z::core::string< E >::string ( const char str,
size_t  len 
)
noexcept

Construct from a cstring of single-byte characters, with a known length.

Parameters
strA cstring, which may or may not be null-terminated.
lenThe length of the string.

All characters are assumed to be compatible with this string's encoding.

◆ string() [6/17]

template<encoding E = utf8>
z::core::string< E >::string ( const wchar_t str)
noexcept

Construct from a cstring of wide characters.

Parameters
strNull-terminated cstring.

Converts the characters in the given cstring to the appropriate encoding for this string.

◆ string() [7/17]

template<encoding E = utf8>
z::core::string< E >::string ( const wchar_t str,
size_t  len 
)
noexcept

Construct from a cstring of wide characters, with a known length.

Parameters
strA cstring, which may or may not be null-terminated.
lenThe length of the string.

All characters are assumed to be compatible with this string's encoding.

◆ string() [8/17]

template<encoding E = utf8>
z::core::string< E >::string ( const std::string< E > &  str)
inlinenoexcept

Construct from a std::string.

Parameters
strThe string to copy.

All characters are assumed to be compatible with this string's encoding.

◆ string() [9/17]

template<encoding E = utf8>
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>
z::core::string< E >::string ( INT  value,
int  base = 10,
int  padSize = 0 
)
inlinenoexcept

Construct from an integer.

Parameters
valueAn integer.
baseThe number's base.
padSizeNumber 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.

◆ string() [10/17]

template<encoding E = utf8>
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>
z::core::string< E >::string ( PTR  pointer)
inlinenoexcept

Construct from a pointer.

Parameters
pointerA 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).

◆ string() [11/17]

template<encoding E = utf8>
template<typename FLT , typename = typename std::enable_if<std::is_floating_point<FLT>::value, FLT>::type>
z::core::string< E >::string ( FLT  value,
int  base = 10,
int  precision = 0,
bool  scientific = true,
int  padSize = 0 
)
inlinenoexcept

Construct from floating-point.

Parameters
valueA floating-point number.
baseThe number's base.
precisionThe number of characters after the decimal point.
scientificWhether to use scientific notation.
padSizeNumber 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).

◆ string() [12/17]

template<encoding E = utf8>
template<typename T , typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
z::core::string< E >::string ( const std::complex< T > &  value,
int  base = 10,
int  precision = 0,
bool  scientific = true,
int  padSize = 0 
)
inlinenoexcept

Construct from complex number.

Parameters
valueA floating-point complex number.
baseThe number's base.
precisionThe number of characters after the decimal point.
scientificWhether to use scientific notation.
padSizeNumber 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).

◆ string() [13/17]

template<encoding E = utf8>
z::core::string< E >::string ( const string< ascii > &  other)
noexcept

Construct from an ASCII string.

Parameters
otherAn ASCII encoded string.

Copies over characters from the given string, converting them to the appropriate encoding scheme for this string.

◆ string() [14/17]

template<encoding E = utf8>
z::core::string< E >::string ( const string< utf8 > &  other)
noexcept

Construct from a UTF-8 string.

Parameters
otherA UTF-8 encoded string.

Copies over characters from the given string, converting them to the appropriate encoding scheme for this string.

◆ string() [15/17]

template<encoding E = utf8>
z::core::string< E >::string ( const string< utf16 > &  other)
noexcept

Construct from a UTF16 string.

Parameters
otherA UTF16 encoded string.

Copies over characters from the given string, converting them to the appropriate encoding scheme for this string.

◆ string() [16/17]

template<encoding E = utf8>
z::core::string< E >::string ( const string< utf32 > &  other)
noexcept

Construct from a UTF32 string.

Parameters
otherA UTF32 encoded string.

Copies over characters from the given string, converting them to the appropriate encoding scheme for this string.

◆ string() [17/17]

template<encoding E = utf8>
z::core::string< E >::string ( string< E > &&  other)
inlinenoexcept

Move constructor.

Moves a string of the same encoding. Just does a mem copy.

Parameters
otherThe string to move.

Member Function Documentation

◆ append() [1/2]

template<encoding E = utf8>
string & z::core::string< E >::append ( const string< E > &  other)
inlinenoexcept

Append another string to the end of this one.

Parameters
otherThe string to append.
Returns
A reference to this string after the other string is appended.
See also
operator+=()

◆ append() [2/2]

template<encoding E = utf8>
string & z::core::string< E >::append ( uint32_t  chr)
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.

Parameters
chrThe character to append, in UTF32 format.
Returns
A reference to this string after the character is appended.
See also
operator+=()

◆ at()

template<encoding E = utf8>
uint32_t z::core::string< E >::at ( int  index) const
overridevirtualnoexcept

Get the character at the given index.

Parameters
indexThe index of the character to get.
Returns
The character at the given index, in UTF32 format.

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.

See also
operator[]()

Implements z::core::indexable< T >.

◆ begin()

template<encoding E = utf8>
stringIterator< E > z::core::string< E >::begin ( ) const
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.

Returns
An iterator on the first character in the string.

Implements z::core::iterable< ITER >.

◆ beginsWith()

template<encoding E = utf8>
bool z::core::string< E >::beginsWith ( const string< E > &  other) const
inlinenoexcept

Check if the string begins with a given sub-string.

Parameters
otherThe sub-string to check for.
Returns
True if this string begins with the given sub-string. False otherwise.

◆ camel()

template<encoding E = utf8>
string z::core::string< E >::camel ( ) const
inlinenoexcept

Get a camelcase version of this string.

Returns
A duplicate of this string, converted to camelcase.
See also
toCamel()

◆ chars()

template<encoding E = utf8>
int z::core::string< E >::chars ( ) const
noexcept

Get the individual character count of the string.

Returns
The number of characters in the string.

For UTF-8 strings, multibyte sequences are counted as a single character.

See also
length()

◆ cipher() [1/2]

template<encoding E = utf8>
string z::core::string< E >::cipher ( const string< E > &  keys,
const string< E > &  values 
) const
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.

Parameters
keysThe characters to find and convert.
valuesThe characters to convert to.
Returns
A string with all the specified characters replaced.

◆ cipher() [2/2]

template<encoding E = utf8>
string z::core::string< E >::cipher ( std::function< uint32_t(uint32_t)>  lambda) const
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.

Parameters
lambdaAn arbitrary function that converts the characters in this string.
Returns
A string with all characters converted according to the lambda.

◆ complex()

template<encoding E = utf8>
std::complex< double > z::core::string< E >::complex ( int  base = 10,
uint32_t  decimal = '.' 
) const
noexcept

Convert this string to a complex value.

Parameters
baseThe base this string is being interpreted as.
decimalThe character used to denote the radix (decimal place).
Returns
The floating-point complex representation of this string, if it is a valid complex float. 0 otherwise.
See also
isComplex()

◆ concat()

template<encoding E = utf8>
string z::core::string< E >::concat ( const string< E > &  other) const
inlinenoexcept

Concatenate two strings.

Parameters
otherThe string to append.
Returns
The concatenation of this and the given string.

Appends the given string to the end of this string's characters and returns the result. This string is not modified.

See also
operator+()

◆ contains() [1/4]

template<encoding E = utf8>
bool z::core::string< E >::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.

example: this->contains({{'A', 'Z'}, {'a', 'z'}, {'0', '9'}}) will return true if this string contains an alphanumeric character.

Parameters
listA list of std::pair objects denoting all valid character ranges.
exclusiveReturn false if this string contains any characters NOT in any of the given ranges.
Returns
Whether this string contained a character in any of the given ranges, or if the exclusive flag is set, whether it contains ONLY characters in the given ranges.

◆ contains() [2/4]

template<encoding E = utf8>
bool z::core::string< E >::contains ( const std::pair< uint32_t, uint32_t > &  range,
bool  exclusive = false 
) const
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.

Parameters
rangeA std::pair denoting the character range.
exclusiveReturn false if this string contains any characters NOT in the given string.
Returns
Whether this string contained a character in the given range, or if the exclusive flag is set, whether it contains ONLY characters in the given range.

◆ contains() [3/4]

template<encoding E = utf8>
bool z::core::string< E >::contains ( const string< E > &  list,
bool  exclusive = false 
) const
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.

Parameters
listA string indicating the list of valid characters.
exclusiveReturn false if this string contains any characters NOT in the given string.
Returns
Whether this string contained any of the characters in the given string, or if the exclusive flag is set, whether it contains ONLY characters in the given string.

◆ contains() [4/4]

template<encoding E = utf8>
bool z::core::string< E >::contains ( uint32_t  first,
uint32_t  last,
bool  exclusive = false 
) const
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.

Parameters
firstThe first character in the range.
lastThe last character in the range.
exclusiveReturn false if this string contains any characters NOT in the given string.
Returns
Whether this string contained a character in the given range, or if the exclusive flag is set, whether it contains ONLY characters in the given range.

◆ count()

template<encoding E = utf8>
int z::core::string< E >::count ( const string< E > &  other) const
noexcept

Count the occurrences of a sub-string.

Parameters
otherThe sub-string to search for.
Returns
The number of times the given sub-string appears in the full string.

◆ cstring()

template<encoding E = utf8>
const char * z::core::string< E >::cstring ( ) const
noexcept

Get the single-byte cstring pointer.

Returns
A pointer to the string data, if this string is in a single-byte format. NULL otherwise.
Examples
hash32.cpp.

◆ cutDuplicates()

template<encoding E = utf8>
string & z::core::string< E >::cutDuplicates ( const string< E > &  other)
noexcept

Remove all sequential duplicates from this string.

Parameters
otherThe string to remove duplicates of.
Returns
A reference to this string after removing duplicates.

Removes all contiguous repetitions of the given sub-string, leaving one instance of the sub-string where the group was.

◆ end()

template<encoding E = utf8>
stringIterator< E > z::core::string< E >::end ( ) const
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.

Returns
An iterator after the last character in the string.

Implements z::core::iterable< ITER >.

◆ endsWith()

template<encoding E = utf8>
bool z::core::string< E >::endsWith ( const string< E > &  other) const
inlinenoexcept

Check if the string ends with a given sub-string.

Parameters
otherThe sub-string to check for.
Returns
True if this string ends with the given sub-string. False otherwise.

◆ filter() [1/5]

template<encoding E = utf8>
string z::core::string< E >::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.

example: this->filter({{'A', 'Z'}, {'a', 'z'}, {'0', '9'}}) will remove all characters that are not alphanumeric.

Parameters
listA list of std::pair objects denoting all valid character ranges.
invertInvert the selection, that is, remove all characters that ARE in the given range.
Returns
A duplicate of this string with all non-matching characters removed.

◆ filter() [2/5]

template<encoding E = utf8>
string z::core::string< E >::filter ( const std::pair< uint32_t, uint32_t > &  range,
bool  invert = false 
) const
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.

Parameters
rangeA std::pair denoting the character range.
invertInvert the selection, that is, remove all characters that ARE in the given range.
Returns
A duplicate of this string with all non-matching characters removed.

◆ filter() [3/5]

template<encoding E = utf8>
string z::core::string< E >::filter ( const string< E > &  list,
bool  invert = false 
) const
noexcept

Filter out all characters not in the given string.

example: this->filter("aeiouyAEIOUY") will remove all non-vowel characters.

Parameters
listA string indicating the list of valid characters.
invertInvert the selection, that is, remove all characters that ARE in the given range.
Returns
A duplicate of this string with all non-matching characters removed.

◆ filter() [4/5]

template<encoding E = utf8>
string z::core::string< E >::filter ( std::function< bool(uint32_t)>  lambda) const
noexcept

Filter out characters based on a function.

example: my_string.filter(z::core::isAlphaNumeric) will remove all characters that are not alphanumeric.

Parameters
lambdaThe 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.
Returns
A duplicate of this string with all non-matching characters removed.

◆ filter() [5/5]

template<encoding E = utf8>
string z::core::string< E >::filter ( uint32_t  first,
uint32_t  last,
bool  invert = false 
) const
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.

Parameters
firstThe first character in the range.
lastThe last character in the range.
invertInvert the selection, that is, remove all characters that ARE in the given range.
Returns
A duplicate of this string with all non-matching characters removed.

◆ find()

template<encoding E = utf8>
int z::core::string< E >::find ( const string< E > &  other,
int  occurrence = 1 
) const
inlinenoexcept

Find a specific occurrence of a sub-string.

Parameters
otherThe sub-string to search for.
occurrenceThe occurrence of the sub-string to find.
Returns
The index of the given occurrence of the sub-string, if that occurrence was found. Otherwise, -1.

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.

◆ findAfter()

template<encoding E = utf8>
int z::core::string< E >::findAfter ( const string< E > &  other,
int  index,
int  occurrence = 1 
) const
inlinenoexcept

Find a specific occurrence of a sub-string.

Parameters
otherThe sub-string to search for.
indexThe index to start at.
occurrenceThe occurrence of the sub-string to find.
Returns
The index of the given occurrence of the sub-string, if that occurrence was found. Otherwise, -1.

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.

◆ findBefore()

template<encoding E = utf8>
int z::core::string< E >::findBefore ( const string< E > &  other,
int  index,
int  occurrence = 1 
) const
noexcept

Reverse-find a specific occurrence of a sub-string.

Parameters
otherThe sub-string to search for.
indexThe index to start at.
occurrenceThe occurrence of the sub-string to find.
Returns
The index of the given occurrence of the sub-string, if that occurrence was found. Otherwise, -1.

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.

◆ findLast()

template<encoding E = utf8>
int z::core::string< E >::findLast ( const string< E > &  other,
int  occurrence = 1 
) const
inlinenoexcept

Reverse-find a specific occurrence of a sub-string.

Parameters
otherThe sub-string to search for.
occurrenceThe occurrence of the sub-string to find.
Returns
The index of the given occurrence of the sub-string, if that occurrence was found. Otherwise, -1.

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.

◆ floating()

template<encoding E = utf8>
double z::core::string< E >::floating ( int  base = 10,
uint32_t  decimal = '.' 
) const
noexcept

Convert this string to a floating-point value.

Parameters
baseThe base this string is being interpreted as.
decimalThe character used to denote the radix (decimal place).
Returns
The floating-point representation of this string, if it is a valid float. 0 otherwise.
See also
isFloating()

◆ format()

template<encoding E = utf8>
constexpr encoding z::core::string< E >::format ( ) const
inlineconstexprnoexcept

Get the encoding of this string.

Returns
An integer indicating this string's encoding.
See also
encoding.h

◆ found()

template<encoding E = utf8>
int z::core::string< E >::found ( const string< E > &  other,
int  occurrence = 1 
) const
inlinenoexcept

Check if a specific occurrence of a sub-string exists.

Parameters
otherThe sub-string to search for.
occurrenceThe occurrence of the sub-string to find.
Returns
True if the given occurrence of the sub-string was found, false otherwise.

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.

◆ foundAt()

template<encoding E = utf8>
bool z::core::string< E >::foundAt ( const string< E > &  other,
int  index 
) const
noexcept

Check if a sub-string is found at the given index.

Parameters
otherThe sub-string to check for.
indexThe index in the string to look at.
Returns
True if the sub-string was found beginning at the given index. False otherwise.

◆ foundEndAt()

template<encoding E = utf8>
bool z::core::string< E >::foundEndAt ( const string< E > &  other,
int  index 
) const
noexcept

Check if a sub-string ends at the given index.

Parameters
otherThe sub-string to check for.
indexThe index in the string to look at.
Returns
True if the sub-string was found ending at the given index. False otherwise.

◆ hash()

template<encoding E = utf8>
hash32 z::core::string< E >::hash ( ) const
noexcept

Compute the CRC32 hash of this string.

Returns
The CRC32 hash of this string.
Examples
hash32.cpp.

◆ increase()

template<encoding E = utf8>
void z::core::string< E >::increase ( int  charCount)
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.

Parameters
charCountThe minimum number of characters this string should be able to contain before reallocating.

◆ insert()

template<encoding E = utf8>
string & z::core::string< E >::insert ( const string< E > &  other,
int  index 
)
noexcept

Insert another string into this one.

Parameters
otherThe string to insert.
indexThe index to insert before.
Returns
A reference to this string after the other string is inserted.

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.

◆ integer()

template<encoding E = utf8>
long z::core::string< E >::integer ( int  base = 10,
uint32_t  decimal = '.' 
) const
noexcept

Convert this string to an integer.

Parameters
baseThe base this string is being interpreted as.
decimalThe character used to denote the radix (decimal place).
Returns
A signed integer representation of this string, if it is a valid integer. 0 otherwise.
Note
If a radix character is encountered before any invalid characters, any text following the radix is ignored.
See also
isInteger()

◆ isComplex()

template<encoding E = utf8>
bool z::core::string< E >::isComplex ( int  base = 10,
uint32_t  decimal = '.' 
) const
inlinenoexcept

Check if this string can convert to a complex value.

Parameters
baseThe base this string is being interpreted as.
decimalThe character that is used as a decimal separator.
Returns
True if the string contains only characters representing a floating-point complex number. False otherwise.

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 +.

See also
isFloating()
complex()

◆ isFloating()

template<encoding E = utf8>
bool z::core::string< E >::isFloating ( int  base = 10,
uint32_t  decimal = '.' 
) const
inlinenoexcept

Check if this string can convert to a floating-point value.

Parameters
baseThe base this string is being interpreted as.
decimalThe character that is used as a decimal separator.
Returns
True if the string contains only characters representing a float. False otherwise.

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.

See also
floating()

◆ isInteger()

template<encoding E = utf8>
bool z::core::string< E >::isInteger ( int  base = 10) const
inlinenoexcept

Check if this string can convert to an integer.

Parameters
baseThe base this string is being interpreted as.
Returns
True if the string contains only characters representing a signed integer. False otherwise.

Valid strings may contain only numeric characters in the given base, and may optionally begin with a + or -.

See also
integer()

◆ length()

template<encoding E = utf8>
int z::core::string< E >::length ( ) const
overridevirtualnoexcept

Get the character count of the string.

Returns
The number of characters in the string.

For UTF-8 strings, multibyte sequences are counted as multiple characters.

See also
chars()

Implements z::core::arrayLike< T, ITER >.

Examples
regexConsole.cpp.

◆ load_minimal()

template<encoding E = utf8>
template<class archive >
void z::core::string< E >::load_minimal ( archive const ar,
std::string< E > const value 
)
inline

Serialization input.

Parameters
arThe input archive.
valueThe string to input from serial archive.

◆ lower()

template<encoding E = utf8>
string z::core::string< E >::lower ( ) const
inlinenoexcept

Get a lowercase version of this string.

Returns
A duplicate of this string, converted to lowercase.
See also
toLower()

◆ nstring()

template<encoding E = utf8>
const uint16_t * z::core::string< E >::nstring ( ) const
noexcept

Get the two-byte cstring pointer.

Returns
A pointer to the string data, if this string is in a two-byte format. NULL otherwise.

◆ numberFormat()

template<encoding E = utf8>
static string z::core::string< E >::numberFormat ( double  value,
int  precision = 0,
bool  forcePrecision = false,
char  decimal = '.',
char  thousands = ',' 
)
staticnoexcept

Create a string from a number with thousands separators.

Parameters
valueThe value to convert to a string.
precisionThe number of digits after the decimal point.
forcePrecisionIf true, always show the specified number of digits after the decimal point, even if they are zeroes.
decimalThe character to use as a decimal separator.
thousandsThe character to use as a thousands separator.
Returns
A string representation of the number with thousands separators and the specified fractional digits.
Examples
word_unscramble.cpp.

◆ operator bool()

template<encoding E = utf8>
constexpr z::core::string< E >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Check if this string contains at least one character.

Returns
True if length() > 0, false otherwise.

◆ operator double()

template<encoding E = utf8>
z::core::string< E >::operator double ( ) const
inlineexplicitnoexcept

Convert this string to a floating-point value.

See also
floating()

◆ operator float()

template<encoding E = utf8>
z::core::string< E >::operator float ( ) const
inlineexplicitnoexcept

Convert this string to a floating-point value.

See also
floating()

◆ operator INT()

template<encoding E = utf8>
template<typename INT , typename = typename std::enable_if<std::is_integral<INT>::value, INT>::type>
z::core::string< E >::operator INT ( ) const
inlineexplicitnoexcept

Convert this string to an integer.

See also
integer()

◆ operator!=()

template<encoding E = utf8>
bool z::core::string< E >::operator!= ( const string< E > &  other) const
inlinenoexcept

Inequality comparison.

Parameters
otherThe string to compare to.
Returns
True if the strings do not exactly match. False otherwise.

◆ operator+()

template<encoding E = utf8>
string z::core::string< E >::operator+ ( const string< E > &  other) const
noexcept

Concatenate two strings.

Parameters
otherThe string to append.
Returns
The concatenation of this and the given string.

Appends the given string to the end of this string's characters and returns the result. This string is not modified.

◆ operator+=()

template<encoding E = utf8>
string & z::core::string< E >::operator+= ( const string< E > &  other)
noexcept

Append another string to the end of this one.

Parameters
otherThe string to append.
Returns
A reference to this string after the other string is appended.
See also
append()

◆ operator<()

template<encoding E = utf8>
bool z::core::string< E >::operator< ( const string< E > &  other) const
noexcept

Less-than comparison.

Parameters
otherThe string to compare to.
Returns
True if this string comes before the given string alphabetically. False otherwise.

◆ operator<=()

template<encoding E = utf8>
bool z::core::string< E >::operator<= ( const string< E > &  other) const
inlinenoexcept

Less-than or equal comparison.

Parameters
otherThe string to compare to.
Returns
True if this string does not come after the given string alphabetically. False otherwise.

◆ operator=() [1/2]

template<encoding E = utf8>
string & z::core::string< E >::operator= ( const string< E > &  other)
noexcept

Assign the contents of this string.

Parameters
otherThe string to copy from.
Returns
A reference to this string after assignment.

Copies all characters from the given string over to this string, replacing current data.

◆ operator=() [2/2]

template<encoding E = utf8>
string & z::core::string< E >::operator= ( string< E > &&  other)
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.

Parameters
otherThe string to move.

◆ operator==()

template<encoding E = utf8>
bool z::core::string< E >::operator== ( const string< E > &  other) const
noexcept

Equality comparison.

Parameters
otherThe string to compare to.
Returns
True if the strings exactly match. False otherwise.

◆ operator>()

template<encoding E = utf8>
bool z::core::string< E >::operator> ( const string< E > &  other) const
noexcept

Greater-than comparison.

Parameters
otherThe string to compare to.
Returns
True if this string comes after the given string alphabetically. False otherwise.

◆ operator>=()

template<encoding E = utf8>
bool z::core::string< E >::operator>= ( const string< E > &  other) const
inlinenoexcept

Greater-than or equal comparison.

Parameters
otherThe string to compare to.
Returns
True if this string does not come before the given string alphabetically. False otherwise.

◆ ordinal()

template<encoding E = utf8>
static string z::core::string< E >::ordinal ( long long  value)
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.

Parameters
valueThe value get the ordinal suffix of.
Returns
A 2-character string representing the ordinal suffix of the given number.

◆ padLeft()

template<encoding E = utf8>
string z::core::string< E >::padLeft ( const string< E > &  other,
int  padSize 
) const
inlinenoexcept

Copy this string, left-padded given character count.

Parameters
otherThe string to pad on the left of the string.
padSizethe number of characters to pad up to.
Returns
A copy of this string after padding.

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.

◆ padLeftIn()

template<encoding E = utf8>
string & z::core::string< E >::padLeftIn ( const string< E > &  other,
int  padSize 
)
noexcept

Left-pad this string up to a given character count.

Parameters
otherThe string to pad on the left of this string.
padSizethe number of characters to pad up to.
Returns
A reference to this string after padding.

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.

◆ padRight()

template<encoding E = utf8>
string z::core::string< E >::padRight ( const string< E > &  other,
int  padSize 
) const
inlinenoexcept

Copy this string, right-padded given character count.

Parameters
otherThe string to pad on the right of the string.
padSizethe number of characters to pad up to.
Returns
A copy of this string after padding.

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.

◆ padRightIn()

template<encoding E = utf8>
string & z::core::string< E >::padRightIn ( const string< E > &  other,
int  padSize 
)
noexcept

Right-pad this string up to a given character count.

Parameters
otherThe string to pad on the right of this string.
padSizethe number of characters to pad up to.
Returns
A reference to this string after padding.

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.

◆ precision()

template<encoding E = utf8>
static string z::core::string< E >::precision ( double  value,
int  precision,
bool  forcePrecision = false 
)
inlinestaticnoexcept

Create a string from a number with a fixed number of decimal places.

Parameters
valueThe value to convert to a string.
precisionThe number of digits after the decimal point.
forcePrecisionIf true, always show the specified number of digits after the decimal point, even if they are zeroes.
Returns
A string representation of the number with the specified fractional digits.

◆ read()

template<encoding E = utf8>
string & z::core::string< E >::read ( std::istream &  stream,
uint32_t  delim = 0 
)
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.

Parameters
streamThe stream to read from.
delimThe delimiter to read until.
Returns
A reference to this string after reading.

◆ readall()

template<encoding E = utf8>
string & z::core::string< E >::readall ( std::istream &  stream)
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.

Parameters
streamThe stream to read from.
Returns
A reference to this string after reading the line.

◆ readln()

template<encoding E = utf8>
string & z::core::string< E >::readln ( std::istream &  stream)
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.

Parameters
streamThe stream to read from.
Returns
A reference to this string after reading the line.
Examples
regexConsole.cpp.

◆ remove() [1/2]

template<encoding E = utf8>
string & z::core::string< E >::remove ( const string< E > &  other,
int  occurrence = 0 
)
noexcept

Remove occurrences of the given sub-string.

Parameters
otherThe sub-string to remove.
occurrenceThe occurrence to remove.
Returns
A reference to this string after the sub-string is removed.

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() [2/2]

template<encoding E = utf8>
string & z::core::string< E >::remove ( int  index,
int  count 
)
noexcept

Remove a subset of the string.

Parameters
indexThe starting index.
countThe number of characters to remove.
Returns
A reference to this string after the characters are removed.

If count is 0, no characters are removed. If count is negative, characters are removed in reverse order.

◆ repeat()

template<encoding E = utf8>
string z::core::string< E >::repeat ( int  count) const
inlinenoexcept

Repeat this string a specific number of times.

Parameters
countthe number of times to repeat this string.
Returns
Resultant string.

◆ replace() [1/2]

template<encoding E = utf8>
string & z::core::string< E >::replace ( const string< E > &  findStr,
const string< E > &  replStr,
int  occurrence = 0 
)
noexcept

Replace occurrences of the given sub-string.

Parameters
findStrThe sub-string to replace.
replStrThe string to replace the sub-string with.
occurrenceThe occurrence to remove.
Returns
A reference to this string after the sub-string is replaced.

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.

◆ replace() [2/2]

template<encoding E = utf8>
string & z::core::string< E >::replace ( int  index,
int  count,
const string< E > &  other 
)
noexcept

Replace a subset of the string.

Parameters
indexThe starting index.
countThe number of characters to remove.
otherThe string to replace the subset with.
Returns
A reference to this string after the characters are replaced.

If count is 0, no characters are replaced. Characters are replaced in forward-order whether count is positive or negative.

◆ save_minimal()

template<encoding E = utf8>
template<class archive >
std::string z::core::string< E >::save_minimal ( archive ar) const
inline

Serialization output.

Parameters
arThe output archive.
Returns
The string to output to serial archive.

◆ size()

template<encoding E = utf8>
size_t z::core::string< E >::size ( ) const
overridevirtualnoexcept

Get the size of the string in memory.

Returns
The number of bytes in memory this string currently consumes.

Implements z::core::sizable.

◆ str()

template<encoding E = utf8>
std::string z::core::string< E >::str ( ) const
inlinenoexcept

Convert to a std::string.

Returns
A std::string representation, always in UTF-8.
Examples
regexConsole.cpp.

◆ substr()

template<encoding E = utf8>
string z::core::string< E >::substr ( int  index,
int  count 
) const
noexcept

Get a sub-string from this string.

Parameters
indexThe sub-string starting index.
countThe number of characters in the sub-string.
Returns
A subset of the original 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".

◆ toCamel()

template<encoding E = utf8>
string & z::core::string< E >::toCamel ( )
noexcept

Convert all characters in the string to camelcase.

Returns
A reference to this string after converting to camelcase.
See also
camel()

◆ toLower()

template<encoding E = utf8>
string & z::core::string< E >::toLower ( )
noexcept

Convert all characters in the string to lowercase.

Returns
A reference to this string after converting to lowercase.
See also
lower()

◆ toUpper()

template<encoding E = utf8>
string & z::core::string< E >::toUpper ( )
noexcept

Convert all characters in the string to uppercase.

Returns
A reference to this string after converting to uppercase.
See also
upper()

◆ trim()

template<encoding E = utf8>
string z::core::string< E >::trim ( const string< E > &  other = "") const
inlinenoexcept

Copies this string and removes padding from both sides of the result.

Parameters
otherThe pad string to remove.
Returns
A copy of this string with right-padding removed.

Removes all occurrences of the given pad string from the left and right sides of this string.

◆ trimIn()

template<encoding E = utf8>
string & z::core::string< E >::trimIn ( const string< E > &  other = "")
inlinenoexcept

Remove padding from the both sides of this string.

Parameters
otherThe pad string to remove.
Returns
A reference to this string after removing padding.

Removes all occurrences of the given pad string from the left and right sides of this string.

◆ trimLeft()

template<encoding E = utf8>
string z::core::string< E >::trimLeft ( const string< E > &  other = "") const
inlinenoexcept

Copies this string and removes padding from the left side of the result.

Parameters
otherThe pad string to remove.
Returns
A copy of this string with left-padding removed.

Removes all occurrences of the given pad string from the left side of this string.

◆ trimLeftIn()

template<encoding E = utf8>
string & z::core::string< E >::trimLeftIn ( const string< E > &  other = "")
inlinenoexcept

Remove padding from the left side of this string.

Parameters
otherThe pad string to remove.
Returns
A reference to this string after removing left-padding.

Removes all occurrences of the given pad string from the left side of this string.

◆ trimRight()

template<encoding E = utf8>
string z::core::string< E >::trimRight ( const string< E > &  other = "") const
inlinenoexcept

Copies this string and removes padding from the right side of the result.

Parameters
otherThe pad string to remove.
Returns
A copy of this string with right-padding removed.

Removes all occurrences of the given pad string from the right side of this string.

◆ trimRightIn()

template<encoding E = utf8>
string & z::core::string< E >::trimRightIn ( const string< E > &  other = "")
inlinenoexcept

Remove padding from the right side of this string.

Parameters
otherThe pad string to remove.
Returns
A reference to this string after removing right-padding.

Removes all occurrences of the given pad string from the right side of this string.

◆ truncate()

template<encoding E = utf8>
string & z::core::string< E >::truncate ( int  index)
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.

Parameters
indexThe index of the first character to remove.
Returns
A reference to this string after the characters are truncated.

◆ type()

template<encoding E = utf8>
int z::core::string< E >::type ( int  base = 10,
uint32_t  decimal = '.' 
) const
noexcept

Determine the most basic type that this string can cast to.

Parameters
baseThe base that numbers are assumed to be in.
decimalThe character that is used as a decimal separator.
Returns
A value from the zstr enum representing the type.
See also
isInteger()
isFloating()
isComplex()
isString()

◆ upper()

template<encoding E = utf8>
string z::core::string< E >::upper ( ) const
inlinenoexcept

Get an uppercase version of this string.

Returns
A duplicate of this string, converted to uppercase.
See also
toUpper()

◆ words()

template<encoding E = utf8>
static string z::core::string< E >::words ( long long  value,
bool  ordinal = false 
)
staticnoexcept

Generate an English representation of a given number.

Parameters
valueThe number to represent in English.
ordinalIf true, output with ordinal suffix.
Returns
A string of English words representing the number's value.
Examples
numberwang.cpp.

◆ write()

template<encoding E = utf8>
void z::core::string< E >::write ( std::ostream &  stream) const
inlinenoexcept

Write string data to a stream in that stream's encoding.

Parameters
streamThe stream to write to.
Examples
regexConsole.cpp, and rot13.cpp.

◆ writeln()

template<encoding E = utf8>
void z::core::string< E >::writeln ( std::ostream &  stream) const
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).

Parameters
streamThe stream to write to.
Examples
file.cpp, generic.cpp, regexConsole.cpp, and rot13.cpp.

◆ wstring()

template<encoding E = utf8>
const uint32_t * z::core::string< E >::wstring ( ) const
noexcept

Get the four-byte cstring pointer.

Returns
A pointer to the string data, if this string is in a four-byte format. NULL otherwise.

Friends And Related Symbol Documentation

◆ operator<<

template<encoding E = utf8>
std::ostream & operator<< ( std::ostream &  ostr,
const z::core::string< E > &  str 
)
friend

Stream output operator.

Parameters
ostrThe output stream.
strThe string to write to the stream.
Returns
A reference to the stream after output.

◆ operator>>

template<encoding E = utf8>
std::istream & operator>> ( std::istream &  istr,
z::core::string< E > &  str 
)
friend

Stream input operator.

Parameters
istrThe input stream.
strThe string to read from the stream.
Returns
A reference to the stream after input.

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