Use internal string trim functions instead of boost algorithm
This commit is contained in:
@@ -20,9 +20,21 @@ typename std::decay< T >::type uppercase( T&& x ) {
|
|||||||
return uppercase( t, t );
|
return uppercase( t, t );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::string ltrim_copy(const T& s)
|
||||||
|
{
|
||||||
|
auto ret = std::string(s.c_str());
|
||||||
|
|
||||||
|
const auto start = ret.find_first_not_of(" \t\n\r\f\v");
|
||||||
|
if (start == std::string::npos)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return ret.substr(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::string trim_copy(const T& s) {
|
std::string rtrim_copy(const T& s)
|
||||||
{
|
{
|
||||||
auto ret = std::string(s.c_str());
|
auto ret = std::string(s.c_str());
|
||||||
|
|
||||||
@@ -32,6 +44,11 @@ std::string trim_copy(const T& s) {
|
|||||||
|
|
||||||
return ret.substr(0, end + 1);
|
return ret.substr(0, end + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::string trim_copy(const T& s)
|
||||||
|
{
|
||||||
|
return ltrim_copy( rtrim_copy(s) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif //OPM_UTILITY_STRING_HPP
|
#endif //OPM_UTILITY_STRING_HPP
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ RstGroup::RstGroup(const std::string* zwel,
|
|||||||
const int *,
|
const int *,
|
||||||
const float * sgrp,
|
const float * sgrp,
|
||||||
const double * xgrp) :
|
const double * xgrp) :
|
||||||
name(trim_copy(zwel[0])),
|
name(rtrim_copy(zwel[0])),
|
||||||
oil_rate_limit(sgrp[VI::SGroup::OilRateLimit]),
|
oil_rate_limit(sgrp[VI::SGroup::OilRateLimit]),
|
||||||
water_rate_limit(sgrp[VI::SGroup::WatRateLimit]),
|
water_rate_limit(sgrp[VI::SGroup::WatRateLimit]),
|
||||||
gas_rate_limit(sgrp[VI::SGroup::GasRateLimit]),
|
gas_rate_limit(sgrp[VI::SGroup::GasRateLimit]),
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ RstWell::RstWell(const RstHeader& header,
|
|||||||
const int * icon,
|
const int * icon,
|
||||||
const float * scon,
|
const float * scon,
|
||||||
const double * xcon) :
|
const double * xcon) :
|
||||||
name(trim_copy(zwel[0])),
|
name(rtrim_copy(zwel[0])),
|
||||||
group(group_arg),
|
group(group_arg),
|
||||||
ij({iwel[VI::IWell::IHead] - 1, iwel[VI::IWell::JHead] - 1}),
|
ij({iwel[VI::IWell::IHead] - 1, iwel[VI::IWell::JHead] - 1}),
|
||||||
k1k2(std::make_pair(iwel[VI::IWell::FirstK] - 1, iwel[VI::IWell::LastK] - 1)),
|
k1k2(std::make_pair(iwel[VI::IWell::FirstK] - 1, iwel[VI::IWell::LastK] - 1)),
|
||||||
|
|||||||
@@ -23,10 +23,9 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
|
|
||||||
#include <opm/common/OpmLog/LogUtil.hpp>
|
#include <opm/common/OpmLog/LogUtil.hpp>
|
||||||
|
|
||||||
|
#include <opm/parser/eclipse/Utility/String.hpp>
|
||||||
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
|
||||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||||
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
||||||
@@ -96,7 +95,7 @@ namespace {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
std::string trim_wgname(const DeckKeyword& keyword, const std::string& wgname_arg, const ParseContext& parseContext, ErrorGuard errors) {
|
std::string trim_wgname(const DeckKeyword& keyword, const std::string& wgname_arg, const ParseContext& parseContext, ErrorGuard errors) {
|
||||||
std::string wgname = boost::algorithm::trim_copy(wgname_arg);
|
std::string wgname = trim_copy(wgname_arg);
|
||||||
if (wgname != wgname_arg) {
|
if (wgname != wgname_arg) {
|
||||||
const auto& location = keyword.location();
|
const auto& location = keyword.location();
|
||||||
std::string msg = "Illegal space: \"" + wgname_arg + "\" found when defining WELL/GROUP in keyword: " + keyword.name() + " at " + location.filename + ":" + std::to_string(location.lineno);
|
std::string msg = "Illegal space: \"" + wgname_arg + "\" found when defining WELL/GROUP in keyword: " + keyword.name() + " at " + location.filename + ":" + std::to_string(location.lineno);
|
||||||
|
|||||||
@@ -181,3 +181,35 @@ BOOST_AUTO_TEST_CASE(strncmp_function) {
|
|||||||
BOOST_CHECK_EQUAL( view.find('X'), std::string::npos);
|
BOOST_CHECK_EQUAL( view.find('X'), std::string::npos);
|
||||||
BOOST_CHECK_EQUAL( view.find('D'), 9);
|
BOOST_CHECK_EQUAL( view.find('D'), 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(trim) {
|
||||||
|
std::string s1 = "ABC";
|
||||||
|
std::string s2 = " ABC";
|
||||||
|
std::string s3 = "ABC ";
|
||||||
|
std::string s4 = " ABC ";
|
||||||
|
std::string s5 = "";
|
||||||
|
std::string s6 = " ";
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(trim_copy(s1) , s1);
|
||||||
|
BOOST_CHECK_EQUAL(trim_copy(s2) , s1);
|
||||||
|
BOOST_CHECK_EQUAL(trim_copy(s3) , s1);
|
||||||
|
BOOST_CHECK_EQUAL(trim_copy(s4) , s1);
|
||||||
|
BOOST_CHECK_EQUAL(trim_copy(s5) , s5);
|
||||||
|
BOOST_CHECK_EQUAL(trim_copy(s6) , s5);
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(ltrim_copy(s1) , s1);
|
||||||
|
BOOST_CHECK_EQUAL(ltrim_copy(s2) , s1);
|
||||||
|
BOOST_CHECK_EQUAL(ltrim_copy(s3) , s3);
|
||||||
|
BOOST_CHECK_EQUAL(ltrim_copy(s4) , s3);
|
||||||
|
BOOST_CHECK_EQUAL(ltrim_copy(s5) , s5);
|
||||||
|
BOOST_CHECK_EQUAL(ltrim_copy(s6) , s5);
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(rtrim_copy(s1) , s1);
|
||||||
|
BOOST_CHECK_EQUAL(rtrim_copy(s2) , s2);
|
||||||
|
BOOST_CHECK_EQUAL(rtrim_copy(s3) , s1);
|
||||||
|
BOOST_CHECK_EQUAL(rtrim_copy(s4) , s2);
|
||||||
|
BOOST_CHECK_EQUAL(rtrim_copy(s5) , s5);
|
||||||
|
BOOST_CHECK_EQUAL(rtrim_copy(s6) , s5);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user