v0.1.8
|
A Utf-8 compliant string. More...
#include <String.hpp>
Public Member Functions | |
String () | |
Initializes to "". | |
String (const String ©) | |
Copies the contents of the string into a new string. More... | |
String (const char *data) | |
Copies raw character array data in a managed string object. More... | |
String (const std::string &data) | |
Copies a raw std::string object. More... | |
String & | operator= (const char *operand) |
Copies the contents of a c string into this string. More... | |
String & | operator= (const String &operand) |
Copies the contents of another string into this string. More... | |
char & | operator[] (Size operand) |
Gets an individual byte from the string at the specified index. | |
const char | operator[] (Size operand) const |
Gets an individual byte from the string at the specified index. | |
bool | operator== (const String &operand) const |
Checks if two strings are equal. More... | |
bool | operator!= (const String &operand) const |
Checks if two strings are not equal. More... | |
template<typename T > | |
String | operator+ (const T &operand) const |
Attempts to convert a data type to string and concatinate it to this string, returning the result. | |
template<typename T > | |
String & | operator+= (const T &operand) |
Attempts to convert a data type to string and concatinate it to this string. | |
bool | operator< (const String &operand) const |
Checks if this string is lexicographically less than another. More... | |
Size | GetSize () const |
Gets the size of the string in bytes. More... | |
Size | GetLength () const |
Counts the number of code points in the string. More... | |
char | GetChar (Size position) const |
Gets an individual character from the string. More... | |
Byte | GetByte (Size position) const |
Gets an individual byte from the string. More... | |
Size | GetCodePoint (Size start, UInt32 *codePoint) const |
Gets an individual code point from the string. More... | |
Boolean | IsEmpty () const |
Checks if the string is empty. More... | |
Boolean | IsNull () const |
Checks if the string is null. More... | |
std::string | GetData () const |
An accessor to the wrapped std::string data. More... | |
const char * | GetCString () const |
Accesses the raw character data from the wrapped std::string object. More... | |
UInt32 | Count (const String &string) const |
Size | FindFirstOf (const String &string, Size offset=0) const |
Finds the first occurence of a string. More... | |
Size | FindFirstOf (const Regex &expression, Size offset=0) const |
Size | FindLastOf (const String &string, Size offset=0) const |
Finds the last occurence of a string. More... | |
Size | FindLastOf (const Regex &expression, Size offset=0) const |
String | SubString (Size offset, Size count=none, bool bytes=false) const |
Gets a part of the string. Supports both Utf-8 and individual bytes. More... | |
bool | Contains (const String &string) const |
Checks if the string contains another string. More... | |
bool | BeginsWith (const String &string) const |
Checks if the string begins with another string. More... | |
bool | EndsWith (const String &string) const |
Checks if the string ends with another string. More... | |
String & | Set (const char *str) |
Sets the value of the string given a c string. More... | |
String & | Set (const String &str) |
Sets the value of the string given another string. More... | |
String & | SetFormat (const char *str,...) |
Sets to a printf like format. More... | |
void | Trim () |
Trims whitespace at the beginning and end of the string. More... | |
void | TrimStart () |
Trims whitespace at the beginning of the string. More... | |
void | TrimEnd () |
Trims whitespace at the end of the string. More... | |
void | Explode (const String &delimiter, FixedList< String > *debris) const |
void | Explode (const String &delimiter, Size limit, FixedList< String > *debris) const |
void | ToLower () |
Converts the entire string to uppercase letters. | |
void | ToUpper () |
Converts the entire string to lowercase letters. | |
String | GetLower () const |
Gets the string as all lowercase letters. | |
String | GetUpper () const |
Gets the string as all uppercase letters. | |
void | RemoveWhitespace () |
Removes all whitespace from within a string. More... | |
void | SetNullToEmpty () |
Changes the string to empty if it is null. | |
void | SetEmptyToNull () |
Changes the string to null if it is empty. | |
template<typename T > | |
bool | Is () const |
Checks if the string can be converted to the given data type. More... | |
template<typename T > | |
T | To () const |
Converts the string to the given data type. More... | |
template<typename T > | |
T | To (const T &fallback) const |
Converts the string to the given data type. More... | |
template<typename Type > | |
CGUL::String | From (Type value) |
template<typename T > | |
CGUL::String | operator+ (const T &operand) const |
template<typename T > | |
CGUL::String & | operator+= (const T &operand) |
Static Public Member Functions | |
static String | FromCodePoint (UInt32 codePoint) |
template<typename Type > | |
static String | From (Type value) |
static String | Format (const char *str,...) |
Static Public Attributes | |
static const Size | none = (Size)-1 |
Friends | |
std::ostream & | operator<< (std::ostream &stream, const String &string) |
A Utf-8 compliant string.
CGUL::String::String | ( | const String & | copy | ) |
Copies the contents of the string into a new string.
copy | The string to copy. |
CGUL::String::String | ( | const char * | data | ) |
Copies raw character array data in a managed string object.
data | A character pointer to a null-terminated string. |
CGUL::String::String | ( | const std::string & | data | ) |
Copies a raw std::string object.
An | std::string value. |
bool CGUL::String::BeginsWith | ( | const String & | string | ) | const |
Checks if the string begins with another string.
string | String to check for. |
bool CGUL::String::Contains | ( | const String & | string | ) | const |
Checks if the string contains another string.
string | String to check for. |
bool CGUL::String::EndsWith | ( | const String & | string | ) | const |
Checks if the string ends with another string.
string | String to check for. |
CGUL::Size CGUL::String::FindFirstOf | ( | const String & | string, |
Size | offset = 0 |
||
) | const |
Finds the first occurence of a string.
string | The string to look for. |
offset | An offset to start looking for the string. |
CGUL::Size CGUL::String::FindLastOf | ( | const String & | string, |
Size | offset = 0 |
||
) | const |
Finds the last occurence of a string.
string | The string to look for. |
offset | A backwards offset to start looking for the string. |
CGUL::Byte CGUL::String::GetByte | ( | Size | position | ) | const |
Gets an individual byte from the string.
position | The index of the byte. |
char CGUL::String::GetChar | ( | Size | position | ) | const |
Gets an individual character from the string.
position | The index of the character. |
CGUL::Size CGUL::String::GetCodePoint | ( | Size | start, |
UInt32 * | codePoint | ||
) | const |
Gets an individual code point from the string.
start | The first byte of the code point. |
codePoint | A pointer to the UInt32 variable to store the code point. |
Example
const char * CGUL::String::GetCString | ( | ) | const |
Accesses the raw character data from the wrapped std::string object.
std::string CGUL::String::GetData | ( | ) | const |
An accessor to the wrapped std::string data.
CGUL::Size CGUL::String::GetLength | ( | ) | const |
Counts the number of code points in the string.
CGUL::Size CGUL::String::GetSize | ( | ) | const |
Gets the size of the string in bytes.
bool CGUL::String::Is | ( | ) | const |
Checks if the string can be converted to the given data type.
CGUL::Boolean CGUL::String::IsEmpty | ( | ) | const |
Checks if the string is empty.
CGUL::Boolean CGUL::String::IsNull | ( | ) | const |
Checks if the string is null.
bool CGUL::String::operator!= | ( | const String & | operand | ) | const |
Checks if two strings are not equal.
operand | The other string. |
CGUL::String CGUL::String::operator+ | ( | const T & | operand | ) | const |
operand | The value to concatenate. |
Attempts to convert the value to a string using standard template library streams.
CGUL::String& CGUL::String::operator+= | ( | const T & | operand | ) |
operand | The value to concatenate. |
Attempts to convert the value to a string using standard template library streams.
bool CGUL::String::operator< | ( | const String & | operand | ) | const |
Checks if this string is lexicographically less than another.
operand | The other string. |
CGUL::String & CGUL::String::operator= | ( | const char * | operand | ) |
Copies the contents of a c string into this string.
operand | The c string or null. |
CGUL::String & CGUL::String::operator= | ( | const String & | operand | ) |
Copies the contents of another string into this string.
operand | The other string. |
bool CGUL::String::operator== | ( | const String & | operand | ) | const |
Checks if two strings are equal.
operand | The other string. |
void CGUL::String::RemoveWhitespace | ( | ) |
Removes all whitespace from within a string.
Removes spaces, tabs and the following whitespaces: \n \v \f \r
CGUL::String & CGUL::String::Set | ( | const char * | str | ) |
Sets the value of the string given a c string.
str | The c string. |
CGUL::String & CGUL::String::Set | ( | const String & | str | ) |
Sets the value of the string given another string.
str | The c string. |
CGUL::String & CGUL::String::SetFormat | ( | const char * | str, |
... | |||
) |
Sets to a printf like format.
str | Printf-like string. |
... | Values. |
CGUL::String CGUL::String::SubString | ( | Size | start, |
Size | count = none , |
||
bool | bytes = false |
||
) | const |
Gets a part of the string. Supports both Utf-8 and individual bytes.
start | The first character to grab. |
count | The number of characters to grab. |
bytes | If true, this method will grab count number of bytes. If false, this method will grab count number of codepoints. |
This method does not support backwards counting (supplying a negative start) like php's substr() and others.
Example
T CGUL::String::To | ( | ) | const |
Converts the string to the given data type.
T CGUL::String::To | ( | const T & | fallback | ) | const |
Converts the string to the given data type.
fallback | The value to set to if the conversion failed. |
void CGUL::String::Trim | ( | ) |
Trims whitespace at the beginning and end of the string.
Removes spaces, tabs and the following whitespaces: \n \v \f \r
Example
void CGUL::String::TrimEnd | ( | ) |
Trims whitespace at the end of the string.
Removes spaces, tabs and the following whitespaces: \n \v \f \r
Example
void CGUL::String::TrimStart | ( | ) |
Trims whitespace at the beginning of the string.
Removes spaces, tabs and the following whitespaces: \n \v \f \r
Example