ExpressionParser: Simplify pi detection
This commit is contained in:
@@ -197,7 +197,6 @@ class ExpressionParser::Tokenizer {
|
|||||||
fCurrentToken = Token(begin, length, _CurrentPos() - length,
|
fCurrentToken = Token(begin, length, _CurrentPos() - length,
|
||||||
TOKEN_CONSTANT);
|
TOKEN_CONSTANT);
|
||||||
fCurrentToken.value = temp.String();
|
fCurrentToken.value = temp.String();
|
||||||
|
|
||||||
} else if (isalpha(*fCurrentChar) && *fCurrentChar != 'x') {
|
} else if (isalpha(*fCurrentChar) && *fCurrentChar != 'x') {
|
||||||
const char* begin = fCurrentChar;
|
const char* begin = fCurrentChar;
|
||||||
while (*fCurrentChar != 0 && (isalpha(*fCurrentChar)
|
while (*fCurrentChar != 0 && (isalpha(*fCurrentChar)
|
||||||
@@ -207,14 +206,10 @@ class ExpressionParser::Tokenizer {
|
|||||||
int32 length = fCurrentChar - begin;
|
int32 length = fCurrentChar - begin;
|
||||||
fCurrentToken = Token(begin, length, _CurrentPos() - length,
|
fCurrentToken = Token(begin, length, _CurrentPos() - length,
|
||||||
TOKEN_IDENTIFIER);
|
TOKEN_IDENTIFIER);
|
||||||
|
} else if (strncmp(fCurrentChar, "π", 2) == 0) {
|
||||||
} else if ((unsigned char)fCurrentChar[0] == 0xCF
|
|
||||||
&& (unsigned char)fCurrentChar[1] == 0x80) {
|
|
||||||
// UTF-8 small greek letter PI
|
|
||||||
fCurrentToken = Token(fCurrentChar, 2, _CurrentPos() - 1,
|
fCurrentToken = Token(fCurrentChar, 2, _CurrentPos() - 1,
|
||||||
TOKEN_IDENTIFIER);
|
TOKEN_IDENTIFIER);
|
||||||
fCurrentChar += 2;
|
fCurrentChar += 2;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int32 type = TOKEN_NONE;
|
int32 type = TOKEN_NONE;
|
||||||
|
|
||||||
@@ -567,14 +562,10 @@ ExpressionParser::_InitArguments(MAPM values[], int32 argumentCount)
|
|||||||
MAPM
|
MAPM
|
||||||
ExpressionParser::_ParseFunction(const Token& token)
|
ExpressionParser::_ParseFunction(const Token& token)
|
||||||
{
|
{
|
||||||
if (strcmp("e", token.string.String()) == 0)
|
if (token.string == "e")
|
||||||
return _ParseFactorial(MAPM(MM_E));
|
return _ParseFactorial(MAPM(MM_E));
|
||||||
else if (strcasecmp("pi", token.string.String()) == 0
|
else if (token.string.ICompare("pi") == 0 || token.string == "π")
|
||||||
|| ((unsigned char)token.string.String()[0] == 0xCF
|
|
||||||
&& (unsigned char)token.string.String()[1] == 0x80)) {
|
|
||||||
// UTF-8 small greek letter PI
|
|
||||||
return _ParseFactorial(MAPM(MM_PI));
|
return _ParseFactorial(MAPM(MM_PI));
|
||||||
}
|
|
||||||
|
|
||||||
// hard coded cases for different count of arguments
|
// hard coded cases for different count of arguments
|
||||||
// supports functions with 3 arguments at most
|
// supports functions with 3 arguments at most
|
||||||
|
|||||||
Reference in New Issue
Block a user