ADDED: TextToInteger()
Custom implementation that returns -1 if it fails (no negative values supported)
This commit is contained in:
parent
d0d81ea545
commit
7615512af1
1 changed files with 20 additions and 0 deletions
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;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue