mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
improvments to tokenizing Scalar
- avoid other degenerate sequences from being treated as a scalar eg, '1-e', '1e+', '1e.2'
This commit is contained in:
@ -186,7 +186,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
|||||||
// has a digit
|
// has a digit
|
||||||
bool hasDigit = isdigit(c);
|
bool hasDigit = isdigit(c);
|
||||||
|
|
||||||
// has a decimal point - cannot be label
|
// has contents that cannot be label
|
||||||
bool notLabel = (c == '.');
|
bool notLabel = (c == '.');
|
||||||
|
|
||||||
// has contents that cannot be scalar
|
// has contents that cannot be scalar
|
||||||
@ -195,26 +195,60 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
|||||||
unsigned int nChar = 0;
|
unsigned int nChar = 0;
|
||||||
charBuffer[nChar++] = c;
|
charBuffer[nChar++] = c;
|
||||||
|
|
||||||
|
// the location of the last '[Ee]' exponent
|
||||||
|
unsigned int exponent = 0;
|
||||||
|
|
||||||
while (is_.get(c))
|
while (is_.get(c))
|
||||||
{
|
{
|
||||||
if (isdigit(c))
|
if (isdigit(c))
|
||||||
{
|
{
|
||||||
hasDigit = true;
|
hasDigit = true;
|
||||||
}
|
}
|
||||||
else if
|
|
||||||
(
|
|
||||||
c == '+'
|
|
||||||
|| c == '-'
|
|
||||||
|| c == '.'
|
|
||||||
|| c == 'E'
|
|
||||||
|| c == 'e'
|
|
||||||
)
|
|
||||||
{
|
|
||||||
notLabel = true;
|
|
||||||
}
|
|
||||||
else if (isalpha(c))
|
else if (isalpha(c))
|
||||||
{
|
{
|
||||||
notLabel = notScalar = true;
|
notLabel = true;
|
||||||
|
|
||||||
|
if (c == 'E' || c == 'e')
|
||||||
|
{
|
||||||
|
if (exponent || !hasDigit)
|
||||||
|
{
|
||||||
|
// mantissa had no digits,
|
||||||
|
// or already saw '[Ee]' before
|
||||||
|
notScalar = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remember this location
|
||||||
|
exponent = nChar;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notScalar = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == '+' || c == '-')
|
||||||
|
{
|
||||||
|
notLabel = true;
|
||||||
|
|
||||||
|
// only allowed once in exponent
|
||||||
|
if (!exponent || exponent+1 != nChar)
|
||||||
|
{
|
||||||
|
notScalar = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// require some digits again
|
||||||
|
hasDigit = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (c == '.')
|
||||||
|
{
|
||||||
|
// notLabel means we already saw '.' or '[Ee]' before
|
||||||
|
// cannot have '.' again
|
||||||
|
if (notLabel)
|
||||||
|
{
|
||||||
|
notScalar = true;
|
||||||
|
}
|
||||||
|
notLabel = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -224,7 +258,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
|||||||
charBuffer[nChar++] = c;
|
charBuffer[nChar++] = c;
|
||||||
if (nChar >= sizeof(charBuffer))
|
if (nChar >= sizeof(charBuffer))
|
||||||
{
|
{
|
||||||
// runaway argument
|
// runaway argument - avoid buffer overflow
|
||||||
t.setBad();
|
t.setBad();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -271,7 +305,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// some else - treat as word
|
// some else: must be a word
|
||||||
t = new word(charBuffer);
|
t = new word(charBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user