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

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

View File

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

View File

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

View File

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

View File

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

View File

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

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);