mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2003 Move conversion from string to double into RiaStdStringTools
This commit is contained in:
@@ -54,3 +54,16 @@ int RiaStdStringTools::toInt(const std::string& s)
|
||||
|
||||
return intValue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiaStdStringTools::toDouble(const std::string& s)
|
||||
{
|
||||
double doubleValue = -1.0;
|
||||
|
||||
char* end;
|
||||
doubleValue = std::strtod(s.data(), &end);
|
||||
|
||||
return doubleValue;
|
||||
}
|
||||
|
@@ -30,5 +30,6 @@ public:
|
||||
static bool isNumber(const std::string& s);
|
||||
|
||||
static int toInt(const std::string& s);
|
||||
static double toDouble(const std::string& s);
|
||||
};
|
||||
|
||||
|
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "RiaDateStringParser.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaStdStringTools.h"
|
||||
|
||||
#include "RifEclipseUserDataKeywordTools.h"
|
||||
|
||||
@@ -283,8 +284,6 @@ bool RifEclipseUserDataParserTools::hasTimeUnit(const std::string& word)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifEclipseUserDataParserTools::hasOnlyValidDoubleValues(const std::vector<std::string>& words, std::vector<double>* doubleValues)
|
||||
{
|
||||
char* end;
|
||||
|
||||
bool onlyValidValues = true;
|
||||
|
||||
for (const auto& word : words)
|
||||
@@ -295,7 +294,7 @@ bool RifEclipseUserDataParserTools::hasOnlyValidDoubleValues(const std::vector<s
|
||||
}
|
||||
else
|
||||
{
|
||||
double doubleVal = strtod(word.data(), &end);
|
||||
double doubleVal = RiaStdStringTools::toDouble(word);
|
||||
doubleValues->push_back(doubleVal);
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "RifKeywordVectorParser.h"
|
||||
|
||||
#include "RiaStdStringTools.h"
|
||||
|
||||
#include "RifEclipseUserDataParserTools.h"
|
||||
|
||||
#include "cvfAssert.h"
|
||||
@@ -90,7 +92,7 @@ void RifKeywordVectorParser::parseData(const QString& data)
|
||||
|
||||
while (RifEclipseUserDataParserTools::isANumber(line))
|
||||
{
|
||||
keywordBasedVector.values.push_back(std::stod(line));
|
||||
keywordBasedVector.values.push_back(RiaStdStringTools::toDouble(line));
|
||||
std::getline(streamData, line);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user