check for empty word/expression in keyType and wordRe IO

This commit is contained in:
Mark Olesen
2009-08-09 09:58:00 +02:00
parent bdbdd25bac
commit 77b2fecc7f
10 changed files with 32 additions and 11 deletions

View File

@ -58,12 +58,22 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& w)
{
// Assign from string. Sets regular expression.
w = t.stringToken();
// flag empty strings as an error
if (w.empty())
{
is.setBad();
FatalIOErrorIn("operator>>(Istream&, keyType&)", is)
<< "empty word/expression "
<< exit(FatalIOError);
return is;
}
}
else
{
is.setBad();
FatalIOErrorIn("operator>>(Istream&, keyType&)", is)
<< "wrong token type - expected word or string found "
<< "wrong token type - expected word or string, found "
<< t.info()
<< exit(FatalIOError);

View File

@ -55,7 +55,7 @@ Foam::Istream& Foam::operator>>(Istream& is, string& s)
{
is.setBad();
FatalIOErrorIn("operator>>(Istream&, string&)", is)
<< "wrong token type - expected string found " << t.info()
<< "wrong token type - expected string, found " << t.info()
<< exit(FatalIOError);
return is;

View File

@ -65,7 +65,8 @@ Foam::Istream& Foam::operator>>(Istream& is, word& w)
{
is.setBad();
FatalIOErrorIn("operator>>(Istream&, word&)", is)
<< "wrong token type - expected word found non-word characters "
<< "wrong token type - expected word, found "
"non-word characters "
<< t.info()
<< exit(FatalIOError);
return is;
@ -75,7 +76,7 @@ Foam::Istream& Foam::operator>>(Istream& is, word& w)
{
is.setBad();
FatalIOErrorIn("operator>>(Istream&, word&)", is)
<< "wrong token type - expected word found "
<< "wrong token type - expected word, found "
<< t.info()
<< exit(FatalIOError);

View File

@ -57,12 +57,22 @@ Foam::Istream& Foam::operator>>(Istream& is, wordRe& w)
{
// Auto-tests for regular expression
w = t.stringToken();
// flag empty strings as an error
if (w.empty())
{
is.setBad();
FatalIOErrorIn("operator>>(Istream&, wordRe&)", is)
<< "empty word/expression "
<< exit(FatalIOError);
return is;
}
}
else
{
is.setBad();
FatalIOErrorIn("operator>>(Istream&, wordRe&)", is)
<< "wrong token type - expected word or string found "
<< "wrong token type - expected word or string, found "
<< t.info()
<< exit(FatalIOError);