Mana
|
#include <optional>
#include <sstream>
#include <string>
#include <vector>
Go to the source code of this file.
Classes | |
struct | FromString< T, std::enable_if_t< std::is_enum_v< T > > > |
struct | FromString< std::optional< T > > |
Functions | |
std::string & | trim (std::string &str) |
Trims spaces off the end and the beginning of the given string. | |
std::string & | toLower (std::string &str) |
Converts the given string to lower case. | |
std::string & | toUpper (std::string &str) |
Converts the given string to upper case. | |
unsigned int | atox (const std::string &str) |
Converts an ascii hexidecimal string to an integer. | |
template<typename T > | |
std::string | toString (const T &arg) |
Converts the given value to a string using std::stringstream. | |
const char * | ipToString (int address) |
Converts the given IP address to a string. | |
std::string | strprintf (char const *,...) |
A safe version of sprintf that returns a std::string of the result. | |
std::string & | replaceCharacters (std::string &str, std::string_view chars, char replacement='_') |
Replaces a set of characters with another character. | |
std::string & | removeColors (std::string &msg) |
Removes colors from a string. | |
bool | startsWith (std::string_view str, std::string_view prefix) |
Returns whether a string starts with a given prefix. | |
bool | endsWith (std::string_view str, std::string_view suffix) |
Returns whether a string ends with a given suffix. | |
bool | isWordSeparator (char chr) |
Tells wether the character is a word separator. | |
std::string | findSameSubstring (const std::string &str1, const std::string &str2) |
bool | getBoolFromString (std::string text, bool def=false) |
Returns a bool value depending on the given string value. | |
template<typename T > | |
void | fromString (const char *str, T &value) |
void | fromString (const char *str, std::string &value) |
void | fromString (const char *str, std::string_view &value) |
void | fromString (const char *str, int &value) |
void | fromString (const char *str, unsigned &value) |
void | fromString (const char *str, unsigned short &value) |
void | fromString (const char *str, float &value) |
void | fromString (const char *str, double &value) |
void | fromString (const char *str, bool &value) |
void | fromString (const char *str, std::vector< int > &value) |
std::string | autocomplete (const std::vector< std::string > &candidates, std::string base) |
Returns the most approaching string of base from candidates. | |
std::string | normalize (const std::string &name) |
Normalize a string, which means lowercase and trim it. | |
std::string | getDirectoryFromURL (const std::string &url) |
Derives a directory from the given URL, stripping the schema and replacing certain invalid characters. | |
std::string | join (const std::vector< std::string > &strings, const char *separator) |
Joins a vector of strings into one string, separated by the given separator. | |
unsigned int atox | ( | const std::string & | str | ) |
Converts an ascii hexidecimal string to an integer.
str | the hex string to convert to an int |
Definition at line 60 of file stringutils.cpp.
std::string autocomplete | ( | const std::vector< std::string > & | candidates, |
std::string | base | ||
) |
Returns the most approaching string of base from candidates.
Definition at line 181 of file stringutils.cpp.
|
inline |
Returns whether a string ends with a given suffix.
Definition at line 128 of file stringutils.h.
std::string findSameSubstring | ( | const std::string & | str1, |
const std::string & | str2 | ||
) |
Definition at line 130 of file stringutils.cpp.
|
inline |
Definition at line 200 of file stringutils.h.
|
inline |
Definition at line 195 of file stringutils.h.
|
inline |
Definition at line 190 of file stringutils.h.
|
inline |
Definition at line 175 of file stringutils.h.
|
inline |
Definition at line 165 of file stringutils.h.
|
inline |
Definition at line 170 of file stringutils.h.
void fromString | ( | const char * | str, |
std::vector< int > & | value | ||
) |
Definition at line 156 of file stringutils.cpp.
void fromString | ( | const char * | str, |
T & | value | ||
) |
Definition at line 160 of file stringutils.h.
|
inline |
Definition at line 180 of file stringutils.h.
|
inline |
Definition at line 185 of file stringutils.h.
bool getBoolFromString | ( | std::string | text, |
bool | def = false |
||
) |
Returns a bool value depending on the given string value.
text | the string used to get the bool value |
Definition at line 144 of file stringutils.cpp.
std::string getDirectoryFromURL | ( | const std::string & | url | ) |
Derives a directory from the given URL, stripping the schema and replacing certain invalid characters.
i.e.: http://www.manasource.org:9601/updates/ -> www.manasource.org_9601/updates/
Definition at line 222 of file stringutils.cpp.
const char * ipToString | ( | int | address | ) |
Converts the given IP address to a string.
The returned string is statically allocated, and shouldn't be freed. It is changed upon the next use of this method.
address | the address to convert to a string |
Definition at line 68 of file stringutils.cpp.
bool isWordSeparator | ( | char | chr | ) |
Tells wether the character is a word separator.
Definition at line 125 of file stringutils.cpp.
std::string join | ( | const std::vector< std::string > & | strings, |
const char * | separator | ||
) |
Joins a vector of strings into one string, separated by the given separator.
Definition at line 245 of file stringutils.cpp.
std::string normalize | ( | const std::string & | name | ) |
Normalize a string, which means lowercase and trim it.
Definition at line 216 of file stringutils.cpp.
std::string & removeColors | ( | std::string & | msg | ) |
Removes colors from a string.
msg | the string to remove the colors from |
Definition at line 114 of file stringutils.cpp.
std::string & replaceCharacters | ( | std::string & | str, |
std::string_view | chars, | ||
char | replacement = '_' |
||
) |
Replaces a set of characters with another character.
str | the string to remove the bad chars from |
chars | the bad characters to remove |
replacement | the character to replace the bad chars with |
Definition at line 102 of file stringutils.cpp.
|
inline |
Returns whether a string starts with a given prefix.
Definition at line 120 of file stringutils.h.
std::string strprintf | ( | char const * | format, |
... | |||
) |
A safe version of sprintf that returns a std::string of the result.
Definition at line 81 of file stringutils.cpp.
std::string & toLower | ( | std::string & | str | ) |
Converts the given string to lower case.
str | the string to convert to lower case |
Definition at line 48 of file stringutils.cpp.
std::string toString | ( | const T & | arg | ) |
Converts the given value to a string using std::stringstream.
arg | the value to convert to a string |
Definition at line 68 of file stringutils.h.
std::string & toUpper | ( | std::string & | str | ) |
Converts the given string to upper case.
str | the string to convert to upper case |
Definition at line 54 of file stringutils.cpp.
std::string & trim | ( | std::string & | str | ) |
Trims spaces off the end and the beginning of the given string.
str | the string to trim spaces off |
Definition at line 29 of file stringutils.cpp.