1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-09-28 17:27:23 +02:00

Refactor is_positive_num() to use C-strings

This makes the future move to C easier, as well as just shows that it's
plain unnecessary to use an std::string here.
This commit is contained in:
Misa 2021-02-11 16:36:22 -08:00 committed by Ethan Lee
parent 825dbac228
commit 89bddf98b6
3 changed files with 4 additions and 4 deletions

View file

@ -284,9 +284,9 @@ static bool VVV_isxdigit(const unsigned char digit)
|| SDL_isdigit(digit); || SDL_isdigit(digit);
} }
bool is_positive_num(const std::string& str, const bool hex) bool is_positive_num(const char* str, const bool hex)
{ {
for (size_t i = 0; i < str.length(); i++) for (size_t i = 0; str[i] != '\0'; ++i)
{ {
if (hex) if (hex)
{ {

View file

@ -24,7 +24,7 @@ bool next_split_s(
bool is_number(const char* str); bool is_number(const char* str);
bool is_positive_num(const std::string& str, const bool hex); bool is_positive_num(const char* str, const bool hex);
bool endsWith(const std::string& str, const std::string& suffix); bool endsWith(const std::string& str, const std::string& suffix);

View file

@ -162,7 +162,7 @@ std::string find_tag(const std::string& buf, const std::string& start, const std
size_t real_start = start_pos + 2 + ((int) hex); size_t real_start = start_pos + 2 + ((int) hex);
std::string number(value.substr(real_start, end - real_start)); std::string number(value.substr(real_start, end - real_start));
if (!is_positive_num(number, hex)) if (!is_positive_num(number.c_str(), hex))
{ {
return ""; return "";
} }