diff --git a/src/cat/TPTScriptInterface.cpp b/src/cat/TPTScriptInterface.cpp index 84f55efb0..a6a386f6d 100644 --- a/src/cat/TPTScriptInterface.cpp +++ b/src/cat/TPTScriptInterface.cpp @@ -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 * words) { if(words->size() < 1) @@ -128,7 +184,7 @@ AnyType TPTScriptInterface::eval(std::deque * words) return tptS_quit(words); break; case TypeNumber: - return NumberType(atoi(rawWord)); + return NumberType(parseNumber(rawWord)); case TypePoint: { int pointX, pointY; diff --git a/src/cat/TPTScriptInterface.h b/src/cat/TPTScriptInterface.h index 3cb0b5fe6..dea284e73 100644 --- a/src/cat/TPTScriptInterface.h +++ b/src/cat/TPTScriptInterface.h @@ -7,6 +7,7 @@ class TPTScriptInterface: public CommandInterface { protected: AnyType eval(std::deque * words); + int parseNumber(char * stringData); AnyType tptS_set(std::deque * words); AnyType tptS_create(std::deque * words); AnyType tptS_delete(std::deque * words);