Mana
|
#include "utils/stringutils.h"
#include <cstring>
#include <algorithm>
#include <cstdarg>
#include <cstdio>
Go to the source code of this file.
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. | |
const char * | ipToString (int address) |
Converts the given IP address to a string. | |
std::string | strprintf (char const *format,...) |
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 | 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) |
Returns a bool value depending on the given string 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.
std::string findSameSubstring | ( | const std::string & | str1, |
const std::string & | str2 | ||
) |
Definition at line 130 of file stringutils.cpp.
void fromString | ( | const char * | str, |
std::vector< int > & | value | ||
) |
Definition at line 156 of file stringutils.cpp.
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.
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 & 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.