mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +00:00
feat(string): add SStrToInt
This commit is contained in:
parent
e51d4cdaa1
commit
3d59699e1b
3 changed files with 70 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,4 +27,6 @@ void SStrLower(char* string);
|
|||
|
||||
const char* SStrStr(const char* string, const char* search);
|
||||
|
||||
int32_t SStrToInt(const char* string);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue