Fixed number with exponent scanner (and simplified that code).

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35249 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2010-01-23 08:31:15 +00:00
parent abc26ba8ad
commit 100dd0cf5c
+41 -21
View File
@@ -137,29 +137,49 @@ class Tokenizer {
BString temp;
const char* begin = fCurrentChar;
bool expectE = true;
bool expectPlusOrMinus = false;
while (*fCurrentChar != 0) {
if (!isdigit(*fCurrentChar)) {
if (*fCurrentChar == 'e' || *fCurrentChar == 'E') {
if (!expectE)
break;
expectE = false;
expectPlusOrMinus = true;
} else if (*fCurrentChar == '+' || *fCurrentChar == '-') {
if (!expectPlusOrMinus)
break;
} else if (!(*fCurrentChar == '.' || *fCurrentChar == ','))
break;
else
expectPlusOrMinus = false;
}
if (*fCurrentChar == ',')
temp << '.';
else
temp << *fCurrentChar;
// optional digits before the comma
while (isdigit(*fCurrentChar)) {
temp << *fCurrentChar;
fCurrentChar++;
}
// optional post comma part
// (required if there are no digits before the comma)
if (*fCurrentChar == '.' || *fCurrentChar == ',') {
temp << '.';
fCurrentChar++;
// optional post comma digits
while (isdigit(*fCurrentChar)) {
temp << *fCurrentChar;
fCurrentChar++;
}
}
// optional exponent part
if (*fCurrentChar == 'e' || *fCurrentChar == 'E') {
temp << *fCurrentChar;
fCurrentChar++;
// optional exponent sign
if (*fCurrentChar == '+' || *fCurrentChar == '-') {
temp << *fCurrentChar;
fCurrentChar++;
}
// required exponent digits
if (!isdigit(*fCurrentChar)) {
throw ParseException("missing exponent in constant",
fCurrentChar - begin);
}
while (isdigit(*fCurrentChar)) {
temp << *fCurrentChar;
fCurrentChar++;
}
}
int32 length = fCurrentChar - begin;
BString test = temp;
test << "&_";