feat(string): add SStrToInt

This commit is contained in:
fallenoak 2020-11-21 13:14:15 -06:00
parent e51d4cdaa1
commit 3d59699e1b
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
3 changed files with 70 additions and 0 deletions

View file

@ -288,3 +288,27 @@ const char* SStrStr(const char* string, const char* search) {
return substring;
}
int32_t SStrToInt(const char* string) {
STORM_ASSERT(string);
int32_t result = 0;
bool negative = false;
if (*string == '-') {
negative = true;
string++;
}
uint32_t digit;
while ((digit = *string - '0') < 10) {
result = digit + (10 * result);
string++;
}
if (negative) {
result = -result;
}
return result;
}