mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 22:58:34 +00:00
[Lua] Resolve stoi Exception (#2736)
* [Lua] Resolve stoi Exception * Change fallback for wp, not really needed for safety * Change to Strings::ToInt
This commit is contained in:
@@ -763,3 +763,10 @@ std::string Strings::Random(size_t length)
|
||||
std::generate_n(str.begin(), length, randchar);
|
||||
return str;
|
||||
}
|
||||
|
||||
// a wrapper for stoi which will return a fallback if the string
|
||||
// fails to cast to a number
|
||||
int Strings::ToInt(const std::string &s, int fallback)
|
||||
{
|
||||
return Strings::IsNumber(s) ? std::stoi(s) : fallback;
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ class Strings {
|
||||
public:
|
||||
static bool Contains(std::vector<std::string> container, std::string element);
|
||||
static bool Contains(const std::string& subject, const std::string& search);
|
||||
static int ToInt(const std::string &s, int fallback = 0);
|
||||
static bool IsNumber(const std::string &s);
|
||||
static bool IsFloat(const std::string &s);
|
||||
static const std::string ToLower(std::string s);
|
||||
|
||||
Reference in New Issue
Block a user