Internal helper class.
More...
#include <StringTools.h>
|
static bool | Contains (const std::string &str, const char c) |
| Will return wether or not a given char is in a string. More...
|
|
static std::string | Replace (const std::string &str, const char find, const std::string &subst) |
| Will replace a part of a string with another string. More...
|
|
static std::string | Replace (const std::string &str, const std::string &find, const std::string &subst) |
| Will replace a part of a string with another string. More...
|
|
static bool | IsNumeric (const std::string &str, const bool allowDecimalPoint=false) |
| Will return true if the given string consists only of digits (including signage) More...
|
|
static bool | ParseNumber (const std::string &str, bool &out_isInt, long double &out_number) |
| Will convert the number in str to a number. More...
|
|
static std::vector< std::string > | SplitString (const std::string &str, const char delimiter) |
| Will split a string by a delimiter char. The delimiter will be excluded! More...
|
|
static std::vector< std::string > | SplitString (const std::string &str, const std::string &delimiter) |
| Will split a string by a delimiter string. The delimiter will be excluded! More...
|
|
static std::string | ToLower (const std::string &str) |
| Will make a string all lower-case. More...
|
|
Internal helper class.
Feel free to use it tho.
Definition at line 13 of file StringTools.h.
◆ Contains()
bool Internal::StringTools::Contains |
( |
const std::string & |
str, |
|
|
const char |
c |
|
) |
| |
|
static |
Will return wether or not a given char is in a string.
Definition at line 5 of file StringTools.cpp.
7 for (
const char& i : str)
◆ IsNumeric()
bool Internal::StringTools::IsNumeric |
( |
const std::string & |
str, |
|
|
const bool |
allowDecimalPoint = false |
|
) |
| |
|
static |
Will return true if the given string consists only of digits (including signage)
Definition at line 56 of file StringTools.cpp.
58 if (str.length() == 0)
return false;
60 bool alreadyParsedDecimalPoint =
false;
61 std::size_t digitCount = 0;
63 for (std::size_t i = 0; i < str.length(); i++)
66 ((str[i] >=
'0') && (str[i] <=
'9')) ||
67 ((str[i] ==
'-') && (i == 0)) ||
68 ((str[i] ==
'.') && (allowDecimalPoint) && (!alreadyParsedDecimalPoint) && (digitCount > 0))
74 if (((str[i] >=
'0') && (str[i] <=
'9'))) digitCount++;
75 if (str[i] ==
'.') alreadyParsedDecimalPoint =
true;
79 return digitCount > 0;
◆ ParseNumber()
bool Internal::StringTools::ParseNumber |
( |
const std::string & |
str, |
|
|
bool & |
out_isInt, |
|
|
long double & |
out_number |
|
) |
| |
|
static |
Will convert the number in str to a number.
Returns wether or not the operation was successful.
Also returns wether the number is an integer, or floating point. If int, cast out_number to int.
Definition at line 82 of file StringTools.cpp.
84 bool isDecimal =
false;
86 if (str.length() == 0)
return false;
87 if (
Contains(str,
'.')) isDecimal =
true;
93 out_number = std::stold(str);
96 catch (std::invalid_argument&)
100 catch (std::out_of_range&)
109 out_number = (
long double)std::stoll(str);
112 catch (std::invalid_argument&)
116 catch (std::out_of_range&)
◆ Replace() [1/2]
std::string Internal::StringTools::Replace |
( |
const std::string & |
str, |
|
|
const char |
find, |
|
|
const std::string & |
subst |
|
) |
| |
|
static |
Will replace a part of a string with another string.
Definition at line 14 of file StringTools.cpp.
18 for (std::size_t i = 0; i < str.length(); i++)
20 if (str[i] != find) ss << str[i];
◆ Replace() [2/2]
std::string Internal::StringTools::Replace |
( |
const std::string & |
str, |
|
|
const std::string & |
find, |
|
|
const std::string & |
subst |
|
) |
| |
|
static |
Will replace a part of a string with another string.
Definition at line 27 of file StringTools.cpp.
29 if (find.length() == 0)
return str;
33 std::size_t posFound = 0;
34 std::size_t lastFound = 0;
36 while (posFound != std::string::npos)
39 posFound = str.find(find, posFound);
41 if (posFound != std::string::npos)
43 ss << str.substr(lastFound, posFound - lastFound) << subst;
44 posFound += find.length();
48 ss << str.substr(lastFound, (str.length()) - lastFound);
◆ SplitString() [1/2]
std::vector< std::string > Internal::StringTools::SplitString |
( |
const std::string & |
str, |
|
|
const char |
delimiter |
|
) |
| |
|
static |
Will split a string by a delimiter char. The delimiter will be excluded!
Definition at line 125 of file StringTools.cpp.
127 if (str.length() == 0)
return std::vector<std::string>();
◆ SplitString() [2/2]
std::vector< std::string > Internal::StringTools::SplitString |
( |
const std::string & |
str, |
|
|
const std::string & |
delimiter |
|
) |
| |
|
static |
Will split a string by a delimiter string. The delimiter will be excluded!
Definition at line 132 of file StringTools.cpp.
134 if (str.length() == 0)
return std::vector<std::string>();
136 std::vector<std::string> parts;
138 if (delimiter.length() == 0)
140 for (std::size_t i = 0; i < str.length(); i++)
142 parts.push_back(std::string({ str[i] }));
147 std::size_t posFound = 0;
148 std::size_t lastFound = 0;
150 while (posFound != std::string::npos)
152 lastFound = posFound;
153 posFound = str.find(delimiter, posFound);
157 if (posFound != std::string::npos)
159 found = str.substr(lastFound, posFound - lastFound);
160 posFound += delimiter.length();
164 found = str.substr(lastFound, str.length() - lastFound);
167 parts.push_back(found);
◆ ToLower()
std::string Internal::StringTools::ToLower |
( |
const std::string & |
str | ) |
|
|
static |
Will make a string all lower-case.
Definition at line 173 of file StringTools.cpp.
175 std::stringstream ss;
176 for (std::size_t i = 0; i < str.length(); i++)
178 if ((str[i] >=
'A') && (str[i] <=
'Z')) ss << (char)(((
int)str[i]) + 32);
179 else if (str[i] == -60) ss << (char)-28;
180 else if (str[i] == -42) ss << (char)-10;
181 else if (str[i] == -36) ss << (char)-4;
The documentation for this class was generated from the following files: