Template Numerical Library version\ main:4e58ea6
|
Class for managing strings. More...
#include <TNL/String.h>
Public Types | |
enum class | SplitSkip { NoSkip , SkipEmpty } |
This enum defines how the operation split of string is to be performed. More... | |
Public Member Functions | |
String ()=default | |
Default constructor. | |
String (const std::string &str) | |
Initialization by std::string. | |
String (const String &)=default | |
Default copy constructor. | |
String (String &&)=default | |
Default move constructor. | |
bool | endsWith (const String &suffix) const |
Checks if the string ends with given suffix. | |
int | getAllocatedSize () const |
Returns size of allocated storage for given string. | |
char * | getData () |
Returns pointer to data. Alias of std::string::data. | |
const char * | getData () const |
Returns pointer to data. Alias of std::string::data. | |
int | getLength () const |
Returns the number of characters in given string. Equivalent to getSize. | |
int | getSize () const |
Returns the number of characters in given string. | |
const char * | getString () const |
Returns pointer to data. | |
operator bool () const | |
Cast to bool operator. | |
bool | operator! () const |
Cast to bool with negation operator. | |
bool | operator!= (char str) const |
This function overloads operator!=. | |
bool | operator!= (const char *str) const |
This function overloads operator!=. | |
bool | operator!= (const std::string &str) const |
This function overloads operator!=. | |
bool | operator!= (const String &str) const |
This function overloads operator!=. | |
String | operator+ (char str) const |
This function concatenates strings and returns a newly constructed string object. | |
String | operator+ (const char *str) const |
This function concatenates C strings str and returns a newly constructed string object. | |
String | operator+ (const std::string &str) const |
This function concatenates C strings str and returns a newly constructed string object. | |
String | operator+ (const String &str) const |
This function concatenates C strings str and returns a newly constructed string object. | |
String & | operator+= (char str) |
This function overloads operator+=. | |
String & | operator+= (const char *str) |
This function overloads operator+=. | |
String & | operator+= (const std::string &str) |
This function overloads operator+=. | |
String & | operator+= (const String &str) |
This function overloads operator+=. | |
String & | operator= (const String &)=default |
Default copy assignment operator. | |
String & | operator= (String &&)=default |
Default move assignment operator. | |
bool | operator== (char str) const |
This function checks whether the given string is equal to str. | |
bool | operator== (const char *str) const |
This function overloads operator==. | |
bool | operator== (const std::string &str) const |
This function overloads operator==. | |
bool | operator== (const String &str) const |
This function overloads operator==. | |
char & | operator[] (int i) |
Operator for accessing particular chars of the string. | |
const char & | operator[] (int i) const |
Operator for accessing particular chars of the string. | |
String | replace (const String &pattern, const String &replaceWith, int count=0) const |
This method replaces part of the string. | |
void | setSize (int size) |
Reserves space for given size. | |
std::vector< String > | split (char separator=' ', SplitSkip skipEmpty=SplitSkip::NoSkip) const |
Splits string into list of strings with respect to given separator. | |
bool | startsWith (const String &prefix) const |
Checks if the string starts with given prefix. | |
String | strip (char strip=' ') const |
Trims/strips this string. | |
Public Member Functions inherited from std::string | |
T | string (T... args) |
T | append (T... args) |
T | assign (T... args) |
T | at (T... args) |
T | back (T... args) |
T | begin (T... args) |
T | c_str (T... args) |
T | capacity (T... args) |
T | cbegin (T... args) |
T | cend (T... args) |
T | clear (T... args) |
T | compare (T... args) |
T | copy (T... args) |
T | crbegin (T... args) |
T | crend (T... args) |
T | data (T... args) |
T | empty (T... args) |
T | end (T... args) |
T | erase (T... args) |
T | find (T... args) |
T | find_first_not_of (T... args) |
T | find_first_of (T... args) |
T | find_last_not_of (T... args) |
T | find_last_of (T... args) |
T | front (T... args) |
T | get_allocator (T... args) |
T | insert (T... args) |
T | length (T... args) |
T | max_size (T... args) |
T | operator= (T... args) |
T | operator[] (T... args) |
T | pop_back (T... args) |
T | push_back (T... args) |
T | rbegin (T... args) |
T | rend (T... args) |
T | replace (T... args) |
T | reserve (T... args) |
T | resize (T... args) |
T | rfind (T... args) |
T | shrink_to_fit (T... args) |
T | size (T... args) |
T | substr (T... args) |
T | swap (T... args) |
Public Member Functions inherited from std::basic_string< Char > | |
T | basic_string (T... args) |
T | append (T... args) |
T | assign (T... args) |
T | at (T... args) |
T | back (T... args) |
T | begin (T... args) |
T | c_str (T... args) |
T | capacity (T... args) |
T | cbegin (T... args) |
T | cend (T... args) |
T | clear (T... args) |
T | compare (T... args) |
T | copy (T... args) |
T | crbegin (T... args) |
T | crend (T... args) |
T | data (T... args) |
T | empty (T... args) |
T | end (T... args) |
T | erase (T... args) |
T | find (T... args) |
T | find_first_not_of (T... args) |
T | find_first_of (T... args) |
T | find_last_not_of (T... args) |
T | find_last_of (T... args) |
T | front (T... args) |
T | get_allocator (T... args) |
T | insert (T... args) |
T | length (T... args) |
T | max_size (T... args) |
T | operator= (T... args) |
T | operator[] (T... args) |
T | pop_back (T... args) |
T | push_back (T... args) |
T | rbegin (T... args) |
T | rend (T... args) |
T | replace (T... args) |
T | reserve (T... args) |
T | resize (T... args) |
T | rfind (T... args) |
T | shrink_to_fit (T... args) |
T | size (T... args) |
T | substr (T... args) |
T | swap (T... args) |
Class for managing strings.
The following example shows common use of String.
In addition to methods of this class, check the following related functions:
|
strong |
|
default |
Default constructor.
Constructs an empty string object.
|
inlinenodiscard |
|
inlinenodiscard |
Returns pointer to data.
It returns the content of the given string as a constant pointer to char.
|
inline |
Cast to bool operator.
This operator converts string to boolean expression (true or false). It returns true if the string is NOT empty. Otherwise it returns false.
|
inline |
Cast to bool with negation operator.
This operator converts string to boolean expression (false or true). It returns true if the string is empty. Otherwise it returns false.
|
inlinenodiscard |
This function overloads operator!=.
It returns true when the given string is NOT equal to str. Otherwise it returns true.
|
inlinenodiscard |
This function overloads operator!=.
It returns true when the given string is NOT equal to str. Otherwise it returns true.
|
inlinenodiscard |
This function overloads operator!=.
It returns true when the given string is NOT equal to str. Otherwise it returns true.
|
inlinenodiscard |
This function overloads operator!=.
It returns true when the given string is NOT equal to str. Otherwise it returns true.
|
inline |
This function overloads operator+=.
Operators for single characters.
Appends character str to this string.
|
inline |
This function overloads operator+=.
Operators for C strings.
It appends the C string str to this string.
|
inline |
This function overloads operator+=.
Operators for std::string.
It appends the C string str to this string.
This function overloads operator+=.
Operators for String.
It appends the C string str to this string.
|
inlinenodiscard |
This function checks whether the given string is equal to str.
It returns true when the given string is equal to str. Otherwise it returns false.
|
inlinenodiscard |
This function overloads operator==.
It returns true when the given string is equal to str. Otherwise it returns false.
|
inlinenodiscard |
This function overloads operator==.
It returns true when the given string is equal to str. Otherwise it returns false.
|
inlinenodiscard |
This function overloads operator==.
It returns true when the given string is equal to str. Otherwise it returns false.
|
inlinenodiscard |
Operator for accessing particular chars of the string.
It returns the character at the position i in given string as a modifiable reference.
|
inlinenodiscard |
Operator for accessing particular chars of the string.
This function overloads operator[]. It returns a reference to the character at position i in given string. The character can not be changed be user.
|
inlinenodiscard |
This method replaces part of the string.
It replaces pattern in this string with a string replaceWith. If parameter count is defined, the function makes replacement only count occurrences, of the given pattern. If count is zero, all pattern occurrences are replaced.
pattern | to be replaced. |
replaceWith | string the pattern will be replaced with. |
count | number of occurrences to be replaced. All occurrences are replaced if count is zero.. |
|
inline |
Reserves space for given size.
Requests to allocate storage space of given size to avoid memory reallocation. It allocates one more byte for the terminating 0.
size | Number of characters. |
|
inlinenodiscard |
Splits string into list of strings with respect to given separator.
This method splits the string into sequence of substrings divided by occurrences of separator. It returns the list of those strings via std::vector. When separator does not appear anywhere in the given string, this function returns a single-element list containing given sting. If skipEmpty equals SkipEmpty no empty substrings are inserted into the resulting container.
separator | is a character separating substrings in given string. |
skipEmpty |
|
inlinenodiscard |
Trims/strips this string.
Removes all 'spaces' from given string except for single 'spaces' between words.
strip | can be used to change the character to be removed. |