TPTScriptInterface: Ability to read hexadecimal constants
This commit is contained in:
parent
010f7790eb
commit
0791f5b0f8
@ -85,10 +85,22 @@ ValueType TPTScriptInterface::testType(std::string word)
|
||||
{
|
||||
if(rawWord[i] == ',' && rawWord[i+1] >= '0' && rawWord[i+1] <= '9')
|
||||
goto parsePoint;
|
||||
else if((rawWord[i] == '#' || rawWord[i] == 'x') &&
|
||||
((rawWord[i+1] >= '0' && rawWord[i+1] <= '9')
|
||||
|| (rawWord[i+1] >= 'a' && rawWord[i+1] <= 'f')
|
||||
|| (rawWord[i+1] >= 'A' && rawWord[i+1] <= 'F')))
|
||||
goto parseNumberHex;
|
||||
else
|
||||
goto parseString;
|
||||
}
|
||||
}
|
||||
parseNumberHex:
|
||||
i++;
|
||||
for(; i < word.length(); i++)
|
||||
if(!((rawWord[i] >= '0' && rawWord[i] <= '9') || (rawWord[i] >= 'a' && rawWord[i] <= 'f') || (rawWord[i] >= 'A' && rawWord[i] <= 'F')))
|
||||
{
|
||||
goto parseString;
|
||||
}
|
||||
return TypeNumber;
|
||||
parsePoint:
|
||||
i++;
|
||||
@ -102,6 +114,50 @@ ValueType TPTScriptInterface::testType(std::string word)
|
||||
return TypeString;
|
||||
}
|
||||
|
||||
int TPTScriptInterface::parseNumber(char * stringData)
|
||||
{
|
||||
char cc;
|
||||
int base = 10;
|
||||
int currentNumber = 0;
|
||||
if(stringData[0] == '#')
|
||||
{
|
||||
stringData++;
|
||||
base = 16;
|
||||
}
|
||||
else if(stringData[0] == '0' && stringData[1] == 'x')
|
||||
{
|
||||
stringData+=2;
|
||||
base = 16;
|
||||
}
|
||||
if(base == 16)
|
||||
{
|
||||
while(cc = *(stringData++))
|
||||
{
|
||||
currentNumber *= base;
|
||||
if(cc >= '0' && cc <= '9')
|
||||
currentNumber += cc - '0';
|
||||
else if(cc >= 'a' && cc <= 'f')
|
||||
currentNumber += (cc - 'A') + 10;
|
||||
else if(cc >= 'A' && cc <= 'F')
|
||||
currentNumber += (cc - 'A') + 10;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(cc = *(stringData++))
|
||||
{
|
||||
currentNumber *= base;
|
||||
if(cc >= '0' && cc <= '9')
|
||||
currentNumber += cc - '0';
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
return currentNumber;
|
||||
}
|
||||
|
||||
AnyType TPTScriptInterface::eval(std::deque<std::string> * words)
|
||||
{
|
||||
if(words->size() < 1)
|
||||
@ -128,7 +184,7 @@ AnyType TPTScriptInterface::eval(std::deque<std::string> * words)
|
||||
return tptS_quit(words);
|
||||
break;
|
||||
case TypeNumber:
|
||||
return NumberType(atoi(rawWord));
|
||||
return NumberType(parseNumber(rawWord));
|
||||
case TypePoint:
|
||||
{
|
||||
int pointX, pointY;
|
||||
|
@ -7,6 +7,7 @@
|
||||
class TPTScriptInterface: public CommandInterface {
|
||||
protected:
|
||||
AnyType eval(std::deque<std::string> * words);
|
||||
int parseNumber(char * stringData);
|
||||
AnyType tptS_set(std::deque<std::string> * words);
|
||||
AnyType tptS_create(std::deque<std::string> * words);
|
||||
AnyType tptS_delete(std::deque<std::string> * words);
|
||||
|
Loading…
Reference in New Issue
Block a user