ADDED: TextToInteger()

Custom implementation that returns -1 if it fails (no negative values supported)
This commit is contained in:
Ray 2019-02-06 14:20:14 +01:00
parent d0d81ea545
commit 7615512af1

View file

@ -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;
}
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------