A general unicode based string class. More...
Public Member Functions | |
Str () | |
Constructs a string. More... | |
Str (const Str &other) | |
Constructs a string as a copy of other. More... | |
Str (const char *theString) | |
Creates a string from the given zero terminated char* string. More... | |
Str (const wchar_t *theString) | |
Creates a string from the given zero terminated wchar_t* string. More... | |
Str (const std::string &theString) | |
Creates a string from the given std::string. More... | |
Str (const std::wstring &theString) | |
Creates a string from the given std::wstring. More... | |
Str (char c) | |
Creates a string from the given char. More... | |
Str & | operator= (const Str &other) |
Assigns other to this string and returns a reference to this string. More... | |
bool | operator== (const Str &rhs) const |
Returns true if this string is equal to the passed string. More... | |
bool | operator!= (const Str &rhs) const |
Returns true if this string is not equal to the passed string. More... | |
bool | operator< (const Str &rhs) const |
Returns true if this string is less than the passed string. More... | |
const Str | operator+ (const Str &rhs) const |
Returns the concatenation of this string and the passed rhs string. More... | |
Str & | operator+= (const Str &rhs) |
Sets this string to the concatenation of this string and the passed rhs string. More... | |
Str | toLower () const |
Returns a lowercase copy of the string. More... | |
Str | toUpper () const |
Returns an uppercase copy of the string. More... | |
Str | trimmedRight () const |
Returns string with trailing whitespace removed. More... | |
Str | trimmedLeft () const |
Returns string with leading whitespace removed. More... | |
Str | trimmed () const |
Returns string with leading and trailing whitespace removed. More... | |
Str | simplified () const |
Returns simplified string. More... | |
std::vector< Str > | split (const Str &delimiters=" ") const |
Splits the string into substrings wherever delimiters occurs, and returns the list of those strings. More... | |
size_t | find (const Str &str, size_t start=0) const |
Returns the position of the first occurrence of str starting from start. More... | |
bool | startsWith (const Str &str) const |
Returns true if the string starts with the given str. More... | |
Str | subStr (size_t start, size_t length=npos) const |
Returns the substring of the string starting with index start and the optional given length. More... | |
void | replace (const Str &before, const Str &after) |
Replaces occurrences of the string before with the string after. More... | |
const wchar_t * | c_str () const |
Returns a null-terminated sequence of wchar_t characters. More... | |
std::string | toStdString () const |
Converts a string to an ascii std::string. Non-ascii characters are replaced by a question mark (?) More... | |
std::wstring | toStdWString () const |
Converts a string to a std::wstring (std unicode string) More... | |
std::string | toUtf8 () const |
Converts a string to a Utf8 encoded string. Non-ascii characters are replaced by their multi-byte UTF8 encoding. More... | |
bool | isEmpty () const |
Returns true if the string has no characters, otherwise returns false. More... | |
size_t | size () const |
Returns the length of the string. More... | |
double | toDouble (bool *ok=NULL) const |
Converts the contents of the string to a double value (if possible) More... | |
double | toDouble (double defaultValue) const |
Converts the contents of the string to a double value (if possible) More... | |
float | toFloat (bool *ok=NULL) const |
Converts the contents of the string to a float value (if possible) More... | |
float | toFloat (float defaultValue) const |
Converts the contents of the string to a float value (if possible) More... | |
int | toInt (bool *ok=NULL) const |
Converts the contents of the string to a integer value (if possible) More... | |
int | toInt (int defaultValue) const |
Converts the contents of the string to a integer value (if possible) More... | |
unsigned int | toUInt (bool *ok=NULL) const |
Converts the contents of the string to an unsigned integer value. More... | |
unsigned int | toUInt (unsigned int defaultValue) const |
Converts the contents of the string to an unsigned integer value. More... | |
Str | arg (const Str &a, int fieldWidth=0, char fillChar= ' ') const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by string a. More... | |
Str | arg (char a, int fieldWidth=0, char fillChar= ' ') const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the char a. More... | |
Str | arg (int a, int fieldWidth=0, char fillChar= ' ') const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the integer a. More... | |
Str | arg (int64_t a, int fieldWidth=0, char fillChar= ' ') const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the 64 bit integer a. More... | |
Str | arg (unsigned int a, int fieldWidth=0, char fillChar= ' ') const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the unsigned integer a. More... | |
Str | arg (uint64_t a, int fieldWidth=0, char fillChar= ' ') const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the 64 bit unsigned integer a. More... | |
Str | arg (float a, int fieldWidth=0, char format= 'g', int precision=-1, char fillChar= ' ') const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the float a. More... | |
Str | arg (double a, int fieldWidth=0, char format= 'g', int precision=-1, char fillChar= ' ') const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the double a. More... | |
void | swap (Str &other) |
Exchanges the contents of the two strings. More... | |
bool | matches (const Str &wildcard) const |
Returns true if this string matches the given wildcard. More... | |
const void * | unspecifiedWCharPointer () const |
Returns unspecified const pointer to the underlying raw wchar_t data array. More... | |
Static Public Member Functions | |
static Str | number (int n) |
Creates a string from the given integer. More... | |
static Str | number (unsigned int n) |
Creates a string from the given unsigned integer. More... | |
static Str | number (float n, char format= 'g', int precision=-1) |
Converts the given number to a string with the specified format. More... | |
static Str | number (double n, char format= 'g', int precision=-1) |
Converts the given number to a string with the specified format. More... | |
static Str | numberFromAddress (const void *ptr) |
Returns a string that is a textual representation of the pointer address. More... | |
static Str | fromUnspecifiedWCharPointer (const void *voidPtr) |
Constructs a new Str object from an unspecified const pointer to raw wchar_t data. More... | |
Static Public Attributes | |
static const size_t | npos = static_cast<size_t>(-1) |
Same as std::string::npos. This value, when used as the value for a count parameter n in string's member functions, roughly indicates "as many as possible". As a return value it is usually used to indicate failure. More... | |
A general unicode based string class.
The class supports interop between std::string and std::wstring, as well as const char*. In addition the class has many convenience methods for string manipulation.
cee::Str::Str | ( | ) |
Constructs a string.
cee::Str::Str | ( | const Str & | other | ) |
Constructs a string as a copy of other.
cee::Str::Str | ( | const char * | theString | ) |
Creates a string from the given zero terminated char* string.
|
explicit |
Creates a string from the given zero terminated wchar_t* string.
|
explicit |
Creates a string from the given std::string.
|
explicit |
Creates a string from the given std::wstring.
|
explicit |
Creates a string from the given char.
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by string a.
a | The string to insert at the lowest x |
fieldWidth | The minimal number of characters the argument will occupy. Positive for right aligned text, negative for left aligned text. |
fillChar | The character that will be inserted if the passed string is shorter than the specified fieldWidth. If the length of a is shorter than fieldWidth, the string will be padded with this character. |
This method searches the current string for the lowest x value, and then replaces all of the lowest occurrence with the passed data. Example of use:
cee::Str cee::Str::arg | ( | char | a, |
int | fieldWidth = 0 , |
||
char | fillChar = ' ' |
||
) | const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the char a.
a | The character to insert at the lowest x |
fieldWidth | The minimal number of characters the argument will occupy. Positive for right aligned text, negative for left aligned text. |
fillChar | The character that will be inserted if the string representation of a is shorter than the specified fieldWidth. If the length of a is shorter than fieldWidth, the string will be padded with this character. |
This method searches the current string for the lowest x value, and then replaces all of the lowest occurrence with the passed data. Example of use:
cee::Str cee::Str::arg | ( | int | a, |
int | fieldWidth = 0 , |
||
char | fillChar = ' ' |
||
) | const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the integer a.
a | The int value to insert at the lowest x |
fieldWidth | The minimal number of characters the argument will occupy. Positive for right aligned text, negative for left aligned text. |
fillChar | The character that will be inserted if the string representation of a is shorter than the specified fieldWidth. If the length of a is shorter than fieldWidth, the string will be padded with this character. |
This method searches the current string for the lowest x value, and then replaces all of the lowest occurrence with the passed data. Example of use:
cee::Str cee::Str::arg | ( | int64_t | a, |
int | fieldWidth = 0 , |
||
char | fillChar = ' ' |
||
) | const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the 64 bit integer a.
a | The value to insert at the lowest x |
fieldWidth | The minimal number of characters the argument will occupy. Positive for right aligned text, negative for left aligned text. |
fillChar | The character that will be inserted if the string representation of a is shorter than the specified fieldWidth. If the length of a is shorter than fieldWidth, the string will be padded with this character. |
cee::Str cee::Str::arg | ( | unsigned int | a, |
int | fieldWidth = 0 , |
||
char | fillChar = ' ' |
||
) | const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the unsigned integer a.
a | The unsigned int value to insert at the lowest x |
fieldWidth | The minimal number of characters the argument will occupy. Positive for right aligned text, negative for left aligned text. |
fillChar | The character that will be inserted if the string representation of a is shorter than the specified fieldWidth. If the length of a is shorter than fieldWidth, the string will be padded with this character. |
This method searches the current string for the lowest x value, and then replaces all of the lowest occurrence with the passed data. Example of use:
cee::Str cee::Str::arg | ( | uint64_t | a, |
int | fieldWidth = 0 , |
||
char | fillChar = ' ' |
||
) | const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the 64 bit unsigned integer a.
a | The value to insert at the lowest x |
fieldWidth | The minimal number of characters the argument will occupy. Positive for right aligned text, negative for left aligned text. |
fillChar | The character that will be inserted if the string representation of a is shorter than the specified fieldWidth. If the length of a is shorter than fieldWidth, the string will be padded with this character. |
cee::Str cee::Str::arg | ( | float | a, |
int | fieldWidth = 0 , |
||
char | format = 'g' , |
||
int | precision = -1 , |
||
char | fillChar = ' ' |
||
) | const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the float a.
a | The float value to insert at the lowest x |
fieldWidth | The minimal number of characters the argument will occupy. Positive for right aligned text, negative for left aligned text. |
format | 'g': default, 'e' : scientific notation (1.234e4). 'f' : Fixed notation (1234.0) |
precision | The precision for floating-point values. Only used for 'f' and 'e' |
fillChar | The character that will be inserted if the string representation of a is shorter than the specified fieldWidth. If the length of a is shorter than fieldWidth, the string will be padded with this character. |
This method searches the current string for the lowest x value, and then replaces all of the lowest occurrence with the passed data. Example of use:
cee::Str cee::Str::arg | ( | double | a, |
int | fieldWidth = 0 , |
||
char | format = 'g' , |
||
int | precision = -1 , |
||
char | fillChar = ' ' |
||
) | const |
Returns a copy of this string with the lowest numbered place marker (e.g. %1, %2,..%99) replaced by the double a.
a | The double value to insert at the lowest x |
fieldWidth | The minimal number of characters the argument will occupy. Positive for right aligned text, negative for left aligned text. |
format | 'g': default, 'e' : scientific notation (1.234e4). 'f' : Fixed notation (1234.0) |
precision | The precision for floating-point values. Only used for 'f' and 'e' |
fillChar | The character that will be inserted if the string representation of a is shorter than the specified fieldWidth. If the length of a is shorter than fieldWidth, the string will be padded with this character. |
This method searches the current string for the lowest x value, and then replaces all of the lowest occurrence with the passed data. Example of use:
const wchar_t * cee::Str::c_str | ( | ) | const |
Returns a null-terminated sequence of wchar_t characters.
size_t cee::Str::find | ( | const Str & | str, |
size_t | start = 0 |
||
) | const |
Returns the position of the first occurrence of str starting from start.
Returns Str::npos if not found
|
static |
Constructs a new Str object from an unspecified const pointer to raw wchar_t data.
It is assumed that the data pointed to by voidPtr is actually a wchar_t*.
bool cee::Str::isEmpty | ( | ) | const |
Returns true if the string has no characters, otherwise returns false.
bool cee::Str::matches | ( | const Str & | wildcard | ) | const |
Returns true if this string matches the given wildcard.
|
static |
Creates a string from the given integer.
|
static |
Creates a string from the given unsigned integer.
|
static |
Converts the given number to a string with the specified format.
n | The number to convert |
format | 'g': default, 'e' : scientific notation (1.234e4). 'f' : Fixed notation (1234.0) |
precision | The precision for floating-point values. Only used for 'f' and 'e' |
|
static |
Converts the given number to a string with the specified format.
n | The number to convert |
format | 'g': default, 'e' : scientific notation (1.234e4). 'f' : Fixed notation (1234.0) |
precision | The precision for floating-point values. Only used for 'f' and 'e' |
|
static |
Returns a string that is a textual representation of the pointer address.
bool cee::Str::operator!= | ( | const Str & | rhs | ) | const |
Returns true if this string is not equal to the passed string.
Returns the concatenation of this string and the passed rhs string.
Sets this string to the concatenation of this string and the passed rhs string.
bool cee::Str::operator< | ( | const Str & | rhs | ) | const |
Returns true if this string is less than the passed string.
Assigns other to this string and returns a reference to this string.
bool cee::Str::operator== | ( | const Str & | rhs | ) | const |
Returns true if this string is equal to the passed string.
Replaces occurrences of the string before with the string after.
cee::Str cee::Str::simplified | ( | ) | const |
Returns simplified string.
Strips leading and trailing whitespace. Replaces sequences of internal whitespace with one space
size_t cee::Str::size | ( | ) | const |
Returns the length of the string.
Splits the string into substrings wherever delimiters occurs, and returns the list of those strings.
delimiters | String containing characters used to split into token strings |
If delimiters does not match anywhere in the string, split() returns a single-element list containing this string.
bool cee::Str::startsWith | ( | const Str & | str | ) | const |
Returns true if the string starts with the given str.
Same as: find(str) == 0
Returns the substring of the string starting with index start and the optional given length.
start | Position of the first character to be copied as a substring. If this is equal to the string length, the function returns an empty string. If this is greater than the string length, it throws out_of_range. Note: The first character is denoted by a value of 0 (not 1). |
length | Number of characters to include in the substring (if the string is shorter, as many characters as possible are used). A value of Str::npos indicates all characters until the end of the string. |
void cee::Str::swap | ( | Str & | other | ) |
Exchanges the contents of the two strings.
other | Modifiable reference to the string that should have its contents swapped. |
double cee::Str::toDouble | ( | bool * | ok = NULL | ) | const |
Converts the contents of the string to a double value (if possible)
ok | If not NULL, this will be set to true if conversion is ok, or to false if not |
double cee::Str::toDouble | ( | double | defaultValue | ) | const |
Converts the contents of the string to a double value (if possible)
defaultValue | The value returned if the conversion failed. |
float cee::Str::toFloat | ( | bool * | ok = NULL | ) | const |
Converts the contents of the string to a float value (if possible)
ok | If not NULL, this will be set to true if conversion is ok, or to false if not |
float cee::Str::toFloat | ( | float | defaultValue | ) | const |
Converts the contents of the string to a float value (if possible)
defaultValue | The value returned if the conversion failed. |
int cee::Str::toInt | ( | bool * | ok = NULL | ) | const |
Converts the contents of the string to a integer value (if possible)
ok | If not NULL, this will be set to true if conversion is ok, or to false if not |
int cee::Str::toInt | ( | int | defaultValue | ) | const |
Converts the contents of the string to a integer value (if possible)
defaultValue | The value returned if the conversion failed. |
cee::Str cee::Str::toLower | ( | ) | const |
Returns a lowercase copy of the string.
std::string cee::Str::toStdString | ( | ) | const |
Converts a string to an ascii std::string. Non-ascii characters are replaced by a question mark (?)
std::wstring cee::Str::toStdWString | ( | ) | const |
Converts a string to a std::wstring (std unicode string)
unsigned int cee::Str::toUInt | ( | bool * | ok = NULL | ) | const |
Converts the contents of the string to an unsigned integer value.
ok | If not NULL, this will be set to true if conversion is ok, or to false if not |
unsigned int cee::Str::toUInt | ( | unsigned int | defaultValue | ) | const |
Converts the contents of the string to an unsigned integer value.
defaultValue | The value returned if the conversion failed. |
cee::Str cee::Str::toUpper | ( | ) | const |
Returns an uppercase copy of the string.
std::string cee::Str::toUtf8 | ( | ) | const |
Converts a string to a Utf8 encoded string. Non-ascii characters are replaced by their multi-byte UTF8 encoding.
cee::Str cee::Str::trimmed | ( | ) | const |
Returns string with leading and trailing whitespace removed.
cee::Str cee::Str::trimmedLeft | ( | ) | const |
Returns string with leading whitespace removed.
cee::Str cee::Str::trimmedRight | ( | ) | const |
Returns string with trailing whitespace removed.
const void * cee::Str::unspecifiedWCharPointer | ( | ) | const |
Returns unspecified const pointer to the underlying raw wchar_t data array.
The actual data pointed to by the return value of this function is the same as that returned byt Str::c_str(), but without the type. It can be safely cast to const wchar_t*.
|
static |
Same as std::string::npos. This value, when used as the value for a count parameter n in string's member functions, roughly indicates "as many as possible". As a return value it is usually used to indicate failure.