#2797 Ensemble curves. Support for text ensemble parameters. Unit test

This commit is contained in:
Bjørn Erik Jensen
2018-05-03 09:53:25 +02:00
parent 736277e0ef
commit 92fd4183a9
18 changed files with 341 additions and 87 deletions

View File

@@ -139,7 +139,7 @@ bool RiaDateStringParser::tryParseMonthFirst(const std::string& s, int& year, in
//--------------------------------------------------------------------------------------------------
bool RiaDateStringParser::tryParseYear(const std::string& s, int &year)
{
if (containsAlphabetic(s)) return false;
if (RiaStdStringTools::containsAlphabetic(s)) return false;
auto today = QDate::currentDate();
int y = RiaStdStringTools::toInt(s);
@@ -158,7 +158,7 @@ bool RiaDateStringParser::tryParseYear(const std::string& s, int &year)
//--------------------------------------------------------------------------------------------------
bool RiaDateStringParser::tryParseMonth(const std::string& s, int &month)
{
if (containsAlphabetic(s))
if (RiaStdStringTools::containsAlphabetic(s))
{
auto sMonth = s;
sMonth = trimString(sMonth);
@@ -190,7 +190,7 @@ bool RiaDateStringParser::tryParseMonth(const std::string& s, int &month)
//--------------------------------------------------------------------------------------------------
bool RiaDateStringParser::tryParseDay(const std::string& s, int &day)
{
if (containsAlphabetic(s)) return false;
if (RiaStdStringTools::containsAlphabetic(s)) return false;
int d = RiaStdStringTools::toInt(s);
if (d >= 1 && d <= 31)
@@ -203,14 +203,6 @@ bool RiaDateStringParser::tryParseDay(const std::string& s, int &day)
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaDateStringParser::containsAlphabetic(const std::string& s)
{
return std::find_if(s.begin(), s.end(), [](char c) { return isalpha(c); }) != s.end();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -42,7 +42,6 @@ private:
static bool tryParseMonth(const std::string& s, int &month);
static bool tryParseDay(const std::string& s, int &day);
static bool containsAlphabetic(const std::string& s);
static std::string trimString(const std::string& s);
};

View File

@@ -76,6 +76,24 @@ double RiaStdStringTools::toDouble(const std::string& s)
return doubleValue;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaStdStringTools::containsAlphabetic(const std::string& s)
{
return std::find_if(s.begin(), s.end(), [](char c) { return isalpha(c); }) != s.end();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaStdStringTools::startsWithAlphabetic(const std::string& s)
{
if (s.empty()) return false;
return isalpha(s[0]);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -35,6 +35,8 @@ public:
static int toInt(const std::string& s);
static double toDouble(const std::string& s);
static bool containsAlphabetic(const std::string& s);
static bool startsWithAlphabetic(const std::string& s);
static std::vector<std::string> splitStringBySpace(const std::string& s);