mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-11 22:08:15 +00:00
ADDED: TextToInteger()
Custom implementation that returns -1 if it fails (no negative values supported)
This commit is contained in:
20
src/text.c
20
src/text.c
@@ -1321,6 +1321,26 @@ const char *TextToPascal(const char *text)
|
|||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get integer value from text
|
||||||
|
// NOTE: Negative values not supported
|
||||||
|
int TextToInteger(const char *text)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
int len = strlen(text);
|
||||||
|
int units = 1;
|
||||||
|
|
||||||
|
for (int i = len - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if ((text[i] > 47) && (text[i] < 58)) result += ((int)text[i] - 48)*units;
|
||||||
|
else { result = -1; break; }
|
||||||
|
|
||||||
|
units *= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user