mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3378 Fix boolean reading form command file.
This commit is contained in:
@@ -86,3 +86,47 @@ void RicfFieldWriter<QString>::writeFieldData(const QString& fieldValue, QTextSt
|
||||
}
|
||||
outputStream << "\"";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfFieldReader<bool>::readFieldData(bool& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
||||
{
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||
QString accumulatedFieldValue;
|
||||
QChar nextChar;
|
||||
QChar currentChar;
|
||||
while (!inputStream.atEnd())
|
||||
{
|
||||
nextChar = errorMessageContainer->peekNextChar(inputStream);
|
||||
if (nextChar.isLetter())
|
||||
{
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
accumulatedFieldValue += currentChar;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Accept TRUE or False in any case combination.
|
||||
bool evaluatesToTrue = QString::compare(accumulatedFieldValue, QString("true"), Qt::CaseInsensitive) == 0;
|
||||
bool evaluatesToFalse = QString::compare(accumulatedFieldValue, QString("false"), Qt::CaseInsensitive) == 0;
|
||||
if (evaluatesToTrue == evaluatesToFalse)
|
||||
{
|
||||
QString formatString("Boolean argument \"%1\" for the command \"%2\" does not evaluate to either true or false");
|
||||
QString errorMessage = formatString.arg(errorMessageContainer->currentArgument).arg(errorMessageContainer->currentCommand);
|
||||
errorMessageContainer->addError(errorMessage);
|
||||
}
|
||||
fieldValue = evaluatesToTrue;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfFieldWriter<bool>::writeFieldData(const bool& fieldValue, QTextStream& outputStream)
|
||||
{
|
||||
// Lower-case true/false is used in the documentation.
|
||||
outputStream << (fieldValue ? "true" : "false");
|
||||
}
|
||||
|
||||
@@ -65,6 +65,19 @@ struct RicfFieldWriter<QString>
|
||||
static void writeFieldData(const QString & fieldValue, QTextStream& outputStream);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RicfFieldReader<bool>
|
||||
{
|
||||
static void readFieldData(bool& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RicfFieldWriter<bool>
|
||||
{
|
||||
static void writeFieldData(const bool& fieldValue, QTextStream& outputStream);
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct RicfFieldReader< caf::AppEnum<T> >
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user