Skip to content
Snippets Groups Projects
Commit 77b2fecc authored by Mark Olesen's avatar Mark Olesen
Browse files

check for empty word/expression in keyType and wordRe IO

parent bdbdd25b
No related branches found
No related tags found
No related merge requests found
...@@ -84,7 +84,7 @@ Istream& operator>>(Istream& is, Scalar& s) ...@@ -84,7 +84,7 @@ Istream& operator>>(Istream& is, Scalar& s)
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, Scalar&)", is) FatalIOErrorIn("operator>>(Istream&, Scalar&)", is)
<< "wrong token type - expected Scalar found " << t.info() << "wrong token type - expected Scalar, found " << t.info()
<< exit(FatalIOError); << exit(FatalIOError);
return is; return is;
......
...@@ -74,7 +74,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Switch& s) ...@@ -74,7 +74,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Switch& s)
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, bool/Switch&)", is) FatalIOErrorIn("operator>>(Istream&, bool/Switch&)", is)
<< "wrong token type - expected bool found " << t << "wrong token type - expected bool, found " << t
<< exit(FatalIOError); << exit(FatalIOError);
return is; return is;
......
...@@ -67,7 +67,7 @@ Foam::Istream& Foam::operator>>(Istream& is, int& i) ...@@ -67,7 +67,7 @@ Foam::Istream& Foam::operator>>(Istream& is, int& i)
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, int&)", is) FatalIOErrorIn("operator>>(Istream&, int&)", is)
<< "wrong token type - expected int found " << t.info() << "wrong token type - expected int, found " << t.info()
<< exit(FatalIOError); << exit(FatalIOError);
return is; return is;
......
...@@ -65,7 +65,7 @@ Foam::Istream& Foam::operator>>(Istream& is, long& l) ...@@ -65,7 +65,7 @@ Foam::Istream& Foam::operator>>(Istream& is, long& l)
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, long&)", is) FatalIOErrorIn("operator>>(Istream&, long&)", is)
<< "wrong token type - expected long found " << t.info() << "wrong token type - expected long, found " << t.info()
<< exit(FatalIOError); << exit(FatalIOError);
return is; return is;
......
...@@ -66,7 +66,7 @@ Foam::Istream& Foam::operator>>(Istream& is, unsigned int& i) ...@@ -66,7 +66,7 @@ Foam::Istream& Foam::operator>>(Istream& is, unsigned int& i)
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, unsigned int&)", is) 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); << exit(FatalIOError);
return is; return is;
......
...@@ -63,7 +63,7 @@ Foam::Istream& Foam::operator>>(Istream& is, unsigned long& val) ...@@ -63,7 +63,7 @@ Foam::Istream& Foam::operator>>(Istream& is, unsigned long& val)
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, unsigned long&)", is) 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); << exit(FatalIOError);
return is; return is;
......
...@@ -58,12 +58,22 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& w) ...@@ -58,12 +58,22 @@ Foam::Istream& Foam::operator>>(Istream& is, keyType& w)
{ {
// Assign from string. Sets regular expression. // Assign from string. Sets regular expression.
w = t.stringToken(); 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 else
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, keyType&)", is) FatalIOErrorIn("operator>>(Istream&, keyType&)", is)
<< "wrong token type - expected word or string found " << "wrong token type - expected word or string, found "
<< t.info() << t.info()
<< exit(FatalIOError); << exit(FatalIOError);
......
...@@ -55,7 +55,7 @@ Foam::Istream& Foam::operator>>(Istream& is, string& s) ...@@ -55,7 +55,7 @@ Foam::Istream& Foam::operator>>(Istream& is, string& s)
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, string&)", is) FatalIOErrorIn("operator>>(Istream&, string&)", is)
<< "wrong token type - expected string found " << t.info() << "wrong token type - expected string, found " << t.info()
<< exit(FatalIOError); << exit(FatalIOError);
return is; return is;
......
...@@ -65,7 +65,8 @@ Foam::Istream& Foam::operator>>(Istream& is, word& w) ...@@ -65,7 +65,8 @@ Foam::Istream& Foam::operator>>(Istream& is, word& w)
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, word&)", is) 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() << t.info()
<< exit(FatalIOError); << exit(FatalIOError);
return is; return is;
...@@ -75,7 +76,7 @@ Foam::Istream& Foam::operator>>(Istream& is, word& w) ...@@ -75,7 +76,7 @@ Foam::Istream& Foam::operator>>(Istream& is, word& w)
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, word&)", is) FatalIOErrorIn("operator>>(Istream&, word&)", is)
<< "wrong token type - expected word found " << "wrong token type - expected word, found "
<< t.info() << t.info()
<< exit(FatalIOError); << exit(FatalIOError);
......
...@@ -57,12 +57,22 @@ Foam::Istream& Foam::operator>>(Istream& is, wordRe& w) ...@@ -57,12 +57,22 @@ Foam::Istream& Foam::operator>>(Istream& is, wordRe& w)
{ {
// Auto-tests for regular expression // Auto-tests for regular expression
w = t.stringToken(); 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 else
{ {
is.setBad(); is.setBad();
FatalIOErrorIn("operator>>(Istream&, wordRe&)", is) FatalIOErrorIn("operator>>(Istream&, wordRe&)", is)
<< "wrong token type - expected word or string found " << "wrong token type - expected word or string, found "
<< t.info() << t.info()
<< exit(FatalIOError); << exit(FatalIOError);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment