Move is_numeric to string utils
This commit is contained in:
parent
22e0c89e39
commit
b5ae6c87de
3 changed files with 6 additions and 7 deletions
|
@ -75,12 +75,6 @@ void console::invoke_command(const std::string_view name, const Arguments argume
|
||||||
console::info(System::Core, "{} is not the name of a valid command or variable!", name.data());
|
console::info(System::Core, "{} is not the name of a valid command or variable!", name.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_number(const std::string_view& s)
|
|
||||||
{
|
|
||||||
return !s.empty() && std::find_if(s.begin(),
|
|
||||||
s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void console::parse_and_invoke_command(const std::string_view command) {
|
void console::parse_and_invoke_command(const std::string_view command) {
|
||||||
const auto tokens = tokenize(command, " ");
|
const auto tokens = tokenize(command, " ");
|
||||||
if(tokens.empty())
|
if(tokens.empty())
|
||||||
|
@ -91,7 +85,7 @@ void console::parse_and_invoke_command(const std::string_view command) {
|
||||||
return ConsoleArgument(true);
|
return ConsoleArgument(true);
|
||||||
} else if(arg == "false") {
|
} else if(arg == "false") {
|
||||||
return ConsoleArgument(false);
|
return ConsoleArgument(false);
|
||||||
} else if(is_number(arg)) {
|
} else if(is_numeric(arg)) {
|
||||||
return ConsoleArgument(std::stoi(arg.data()));
|
return ConsoleArgument(std::stoi(arg.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ std::string replace_substring(const std::string_view string, const std::string_v
|
||||||
|
|
||||||
bool string_contains(const std::string_view a, const std::string_view b);
|
bool string_contains(const std::string_view a, const std::string_view b);
|
||||||
bool string_starts_with(const std::string_view haystack, const std::string_view needle);
|
bool string_starts_with(const std::string_view haystack, const std::string_view needle);
|
||||||
|
bool is_numeric(const std::string_view string);
|
||||||
|
|
||||||
std::vector<std::string> tokenize(const std::string_view string, const std::string_view& delimiters = ",");
|
std::vector<std::string> tokenize(const std::string_view string, const std::string_view& delimiters = ",");
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,10 @@ bool string_starts_with(const std::string_view haystack, const std::string_view
|
||||||
&& std::equal(needle.begin(), needle.end(), haystack.begin());
|
&& std::equal(needle.begin(), needle.end(), haystack.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_numeric(const std::string_view string) {
|
||||||
|
return std::find_if(string.begin(), string.end(), [](unsigned char c) { return !std::isdigit(c); }) == string.end();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> tokenize(const std::string_view string, const std::string_view& delimiters) {
|
std::vector<std::string> tokenize(const std::string_view string, const std::string_view& delimiters) {
|
||||||
std::vector<std::string> tokens;
|
std::vector<std::string> tokens;
|
||||||
|
|
||||||
|
|
Reference in a new issue