![]() |
Gorgon Game Engine
|
Contains string related functions and classes. This namespace is not yet utf8 aware. More...
Classes | |
struct | CanBeStringified |
struct | CaseInsensitiveLess |
class | IllegalTokenError |
This error will be thrown if a parsing function encounters with an illegal token. More... | |
class | ParseError |
This error will be thrown if a parsing function encounters with a general error. More... | |
class | Tokenizer |
Tokenizer is a forward iterator that tokenizes a given string. More... | |
Enumerations | |
enum | LineEnding { None, LF, Unix, CR, Mac, CRLF, Standard, Windows, Mixed } |
Line ending types. More... | |
enum | QuoteType { None, Single, Double, Both } |
Functions | |
bool | AppendUnicode (std::string &s, Char c) |
Appends a unicode code point to the string. More... | |
int | CaseInsensitiveCompare (const std::string &left, const std::string &right) |
Compares two strings case insensitive. Works similar to strcmp. More... | |
template<class ... P_> | |
std::string | Concat (const P_ &... rest) |
Streams the given parameters into a stringstream and returns the result, effectively concatinating all parameters. More... | |
std::string | Extract (std::string &original, char marker, bool trim=false) |
Extracts the part of the string up to the given marker. More... | |
std::string | Extract (std::string &original, const std::string &marker, bool trim=false) |
Extracts the part of the string up to the given marker. More... | |
std::string | Extract_UseQuotes (std::string &original, char marker, QuoteType quotetype=QuoteType::Both) |
Extracts the part of the string up to the given marker. More... | |
std::string | FixLineEndings (const std::string &in, LineEnding type=LineEnding::Standard) |
Fixes/changes line endings. More... | |
std::string | From (const Resource::GID::Type &value) |
Creates a string from a GID. More... | |
template<class T_ > | |
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type | From (const T_ &e) |
template<class T_ > | |
std::string | From (const T_ &item) |
Creates a string from the given data. More... | |
bool | InsertUnicode (std::string &s, std::size_t pos, Char c) |
Appends a unicode code point to the string. More... | |
template<class T_ > | |
std::string | Join (const T_ &vec, const std::string &glue=", ") |
Joins a list of strings to a single string using the given glue text. More... | |
std::string | PadEnd (std::string str, std::size_t len, char pad=' ') |
Pads the string to the given number of characters from the start. More... | |
std::string | PadStart (std::string str, std::size_t len, char pad=' ') |
Pads the string to the given number of characters from the start. More... | |
template<class T_ > | |
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, T_ >::type | Parse (const std::string &text) |
std::string | Replace (std::string str, const std::string &find, const std::string &replace) |
String replace that does not use regex. More... | |
template<class T_ > | |
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, T_ >::type | To (const std::string &text) |
template<class T_ > | |
T_ | To (const std::string &value) |
Converts a string to another type. More... | |
std::string | ToLower (std::string str) |
Converts the given string to lowercase. More... | |
std::string | ToUpper (std::string str) |
Converts the given string to uppercase. More... | |
std::string | Trim (std::string str, const std::string &chars=" \t\n\r") |
Strips whitespace around the given string both from start and end. More... | |
std::string | TrimEnd (std::string str, const std::string &chars=" \t\n\r") |
Strips the whitespace at the end of a string. More... | |
std::string | TrimStart (std::string str, const std::string &chars=" \t\n\r") |
Strips the whitespace from the start of a string. More... | |
int | UnicodeGlyphCount (const std::string &s) |
int | UnicodeUTF8Bytes (Char c) |
int | UTF8Bytes (char c) |
Returns the number of bytes used by the next UTF8 codepoint. More... | |
Contains string related functions and classes. This namespace is not yet utf8 aware.
|
strong |
|
strong |
bool Gorgon::String::AppendUnicode | ( | std::string & | s, |
Char | c | ||
) |
Appends a unicode code point to the string.
If the given char is valid, this function will return true. Otherwise, it will place a three byte long replacement character and returns false.
References UnicodeUTF8Bytes().
int Gorgon::String::CaseInsensitiveCompare | ( | const std::string & | left, |
const std::string & | right | ||
) |
Compares two strings case insensitive. Works similar to strcmp.
std::string Gorgon::String::Concat | ( | const P_ &... | rest | ) |
Streams the given parameters into a stringstream and returns the result, effectively concatinating all parameters.
std::string Gorgon::String::Extract | ( | std::string & | original, |
char | marker, | ||
bool | trim = false |
||
) |
Extracts the part of the string up to the given marker.
Extracted string and the marker is removed from the original string. If the given string does not contain marker, entire string will be extracted. It is possible to tokenize the given string using repeated calls to this function. However, its more convenient to use Tokenizer.
original | string that will be processed. This string will be modified by the program |
marker | character that will be searched. |
trim | if set, both extracted and the remaining part of the string |
References Gorgon::swap(), TrimEnd(), and TrimStart().
std::string Gorgon::String::Extract | ( | std::string & | original, |
const std::string & | marker, | ||
bool | trim = false |
||
) |
Extracts the part of the string up to the given marker.
Extracted string and the marker is removed from the original string. If the given string does not contain marker, entire string will be extracted. It is possible to tokenize the given string using repeated calls to this function. However, its more convenient to use Tokenizer.
original | string that will be processed. This string will be modified by the program |
marker | string that will be searched. |
trim | if set, both extracted and the remaining part of the string |
References Gorgon::swap(), TrimEnd(), and TrimStart().
std::string Gorgon::String::Extract_UseQuotes | ( | std::string & | original, |
char | marker, | ||
QuoteType | quotetype = QuoteType::Both |
||
) |
Extracts the part of the string up to the given marker.
This function will skipped quoted sections of the string. Both single and double quotes can be considered, however, double quotes should match with double quotes and single quotes should match with single quotes. A different quote type inside quote region is ignored. Extracted string and the marker is removed from the original string. If the given string does not contain marker outside the quotes, entire string will be extracted. It is possible to tokenize the given string using repeated calls to this function. Unbalanced quotes will be treated ending at the end of the string.
original | string that will be processed. This string will be modified by the program |
marker | string that will be searched. It is possible to specify quote as a marker. |
quotetype | controls which type of quotes will be considered. |
References None, Single, and Gorgon::swap().
std::string FixLineEndings | ( | const std::string & | in, |
LineEnding | type = LineEnding::Standard |
||
) |
Fixes/changes line endings.
If none is supplied, all line endings will be removed. If mixed is set, nothing will be done.
std::string Gorgon::String::From | ( | const Resource::GID::Type & | value | ) |
Creates a string from a GID.
References Type::AsInteger().
std::enable_if<decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string>::type Gorgon::String::From | ( | const T_ & | e | ) |
std::string Gorgon::String::From | ( | const T_ & | item | ) |
Creates a string from the given data.
Similar to to_string but allows conversion of a type if it can be casted or streamed to output. Also uses std::to_string where possible.
bool Gorgon::String::InsertUnicode | ( | std::string & | s, |
std::size_t | pos, | ||
Char | c | ||
) |
Appends a unicode code point to the string.
If the given char is valid, this function will return true. Otherwise, it will place a three byte long replacement character and returns false. pos is the byte offset to insert the character.
References UnicodeUTF8Bytes().
std::string Gorgon::String::Join | ( | const T_ & | vec, |
const std::string & | glue = ", " |
||
) |
Joins a list of strings to a single string using the given glue text.
std::string Gorgon::String::PadEnd | ( | std::string | str, |
std::size_t | len, | ||
char | pad = ' ' |
||
) |
Pads the string to the given number of characters from the start.
This function is not utf aware.
std::string Gorgon::String::PadStart | ( | std::string | str, |
std::size_t | len, | ||
char | pad = ' ' |
||
) |
Pads the string to the given number of characters from the start.
This function is not utf aware.
std::enable_if<decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, T_>::type Gorgon::String::Parse | ( | const std::string & | text | ) |
References gorgon__enum_tr_loc().
std::string Gorgon::String::Replace | ( | std::string | str, |
const std::string & | find, | ||
const std::string & | replace | ||
) |
String replace that does not use regex.
Works faster than regex variant. This function is not utf aware.
str | is the string to process |
find | is the substrings to be replaced |
replace | is the string to place instead of find. Can be empty string. |
std::enable_if<decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, T_>::type Gorgon::String::To | ( | const std::string & | text | ) |
T_ Gorgon::String::To | ( | const std::string & | value | ) |
Converts a string to another type.
Works for integral types and Gorgon classes including Point, Size, etc... There is no error handling. If conversion does not work, you may end up with uninitialized object. This system will be fixed at a later point.
std::string Gorgon::String::ToLower | ( | std::string | str | ) |
Converts the given string to lowercase.
This function is not utf aware.
std::string Gorgon::String::ToUpper | ( | std::string | str | ) |
Converts the given string to uppercase.
This function is not utf aware.
std::string Gorgon::String::Trim | ( | std::string | str, |
const std::string & | chars = " \t\n\r" |
||
) |
Strips whitespace around the given string both from start and end.
This function is not utf aware.
str | is the string to process |
chars | is the characters to be considered as whitespace |
std::string Gorgon::String::TrimEnd | ( | std::string | str, |
const std::string & | chars = " \t\n\r" |
||
) |
Strips the whitespace at the end of a string.
This function is not utf aware.
str | is the string to process |
chars | is the characters to be considered as whitespace |
std::string Gorgon::String::TrimStart | ( | std::string | str, |
const std::string & | chars = " \t\n\r" |
||
) |
Strips the whitespace from the start of a string.
This function is not utf aware.
str | is the string to process |
chars | is the characters to be considered as whitespace |
int Gorgon::String::UnicodeGlyphCount | ( | const std::string & | s | ) |
References UTF8Bytes().
int Gorgon::String::UnicodeUTF8Bytes | ( | Char | c | ) |
int Gorgon::String::UTF8Bytes | ( | char | c | ) |
Returns the number of bytes used by the next UTF8 codepoint.