diff --git a/examples/opmpack.cpp b/examples/opmpack.cpp index 8444a06df..f8536a94b 100644 --- a/examples/opmpack.cpp +++ b/examples/opmpack.cpp @@ -17,6 +17,7 @@ along with OPM. If not, see . */ +#include #include #include diff --git a/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp b/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp index bfd1389a3..e85e09456 100644 --- a/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp +++ b/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.hpp @@ -24,7 +24,6 @@ #include #include #include -#include /* The RestartConfig class internalizes information of when (at which diff --git a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp index b869b51eb..b7c54ce36 100644 --- a/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp +++ b/opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp @@ -22,8 +22,6 @@ #include #include -#include - #include #include #include diff --git a/opm/parser/eclipse/Units/Units.hpp b/opm/parser/eclipse/Units/Units.hpp index a5f474514..5c6d64cfb 100644 --- a/opm/parser/eclipse/Units/Units.hpp +++ b/opm/parser/eclipse/Units/Units.hpp @@ -236,7 +236,7 @@ namespace Opm { * \code * using namespace Opm::unit; * std::transform(p.begin(), p.end(), p.begin(), - * boost::bind(convert::to, _1, psia)); + * std::bind(convert::to, std::placeholders::_1, psia)); * \endcode * * @param[in] q Physical quantity, measured in SI units. diff --git a/opm/parser/eclipse/Utility/String.hpp b/opm/parser/eclipse/Utility/String.hpp index 9bef51366..f6f48af93 100644 --- a/opm/parser/eclipse/Utility/String.hpp +++ b/opm/parser/eclipse/Utility/String.hpp @@ -3,7 +3,9 @@ #include #include +#include #include +#include namespace Opm { @@ -50,5 +52,57 @@ std::string trim_copy(const T& s) { return ltrim_copy( rtrim_copy(s) ); } + + +template +void replaceAll(T& data, const T& toSearch, const T& replace) +{ + // Get the first occurrence + size_t pos = data.find(toSearch); + + // Repeat till end is reached + while (pos != std::string::npos) + { + // Replace this occurrence of Sub String + data.replace(pos, toSearch.size(), replace); + // Get the next occurrence from the current position + pos = data.find(toSearch, pos + replace.size()); + } } + + +inline std::vector split_string(const std::string& input, + char delimiter) +{ + std::vector result; + std::string token; + std::istringstream tokenStream(input); + while (std::getline(tokenStream, token, delimiter)) + result.push_back(token); + + return result; +} + + +inline std::vector split_string(const std::string& input, + const std::string& delimiters) +{ + std::vector result; + std::string::size_type start = 0; + while (start < input.size()) { + auto end = input.find_first_of(delimiters, start); + if (end == std::string::npos) { + result.push_back(input.substr(start)); + end = input.size() - 1; + } else if (end != start) + result.push_back(input.substr(start, end-start)); + + start = end + 1; + } + + return result; +} + +} + #endif //OPM_UTILITY_STRING_HPP diff --git a/src/opm/output/eclipse/AggregateWellData.cpp b/src/opm/output/eclipse/AggregateWellData.cpp index b3a0ed076..e4e33eff4 100644 --- a/src/opm/output/eclipse/AggregateWellData.cpp +++ b/src/opm/output/eclipse/AggregateWellData.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include diff --git a/src/opm/parser/eclipse/Deck/DeckItem.cpp b/src/opm/parser/eclipse/Deck/DeckItem.cpp index d34953b25..e9b74b443 100644 --- a/src/opm/parser/eclipse/Deck/DeckItem.cpp +++ b/src/opm/parser/eclipse/Deck/DeckItem.cpp @@ -20,8 +20,7 @@ #include #include #include - -#include +#include #include #include @@ -261,9 +260,7 @@ void DeckItem::push_backDummyDefault() { } std::string DeckItem::getTrimmedString( size_t index ) const { - return boost::algorithm::trim_copy( - this->value_ref< std::string >().at( index ) - ); + return trim_copy(this->value_ref< std::string >().at(index)); } double DeckItem::getSIDouble( size_t index ) const { diff --git a/src/opm/parser/eclipse/EclipseState/EclipseState.cpp b/src/opm/parser/eclipse/EclipseState/EclipseState.cpp index 50fdd22c4..398ec62ca 100644 --- a/src/opm/parser/eclipse/EclipseState/EclipseState.cpp +++ b/src/opm/parser/eclipse/EclipseState/EclipseState.cpp @@ -19,8 +19,6 @@ #include -#include - #include #include @@ -86,7 +84,9 @@ bool enable3DPropsTesting() { const auto& titleKeyword = deck.getKeyword( "TITLE" ); const auto& item = titleKeyword.getRecord( 0 ).getItem( 0 ); std::vector itemValue = item.getData(); - m_title = boost::algorithm::join( itemValue, " " ); + for (const auto& entry : itemValue) + m_title += entry + ' '; + m_title.pop_back(); } initTransMult(); diff --git a/src/opm/parser/eclipse/EclipseState/Grid/PinchMode.cpp b/src/opm/parser/eclipse/EclipseState/Grid/PinchMode.cpp index f79712ca5..3bd4c14f7 100644 --- a/src/opm/parser/eclipse/EclipseState/Grid/PinchMode.cpp +++ b/src/opm/parser/eclipse/EclipseState/Grid/PinchMode.cpp @@ -17,8 +17,10 @@ along with OPM. If not, see . */ -#include #include +#include + +#include namespace Opm { @@ -44,8 +46,7 @@ namespace Opm { } ModeEnum PinchModeFromString(const std::string& stringValue) { - std::string s(stringValue); - boost::algorithm::trim(s); + std::string s = trim_copy(stringValue); ModeEnum mode; if (s == "ALL") { mode = ModeEnum::ALL; } diff --git a/src/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.cpp b/src/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.cpp index 328d390ae..cd0bee69b 100644 --- a/src/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.cpp +++ b/src/opm/parser/eclipse/EclipseState/IOConfig/RestartConfig.cpp @@ -18,13 +18,12 @@ */ #include +#include #include #include #include #include -#include - #include #include @@ -686,7 +685,7 @@ void RestartConfig::handleScheduleSection(const SCHEDULESection& schedule, const found_mnemonic_RESTART = mnemonic.find("RESTART="); if (found_mnemonic_RESTART != std::string::npos) { std::string restart_no = mnemonic.substr(found_mnemonic_RESTART+8, mnemonic.size()); - restart = boost::lexical_cast(restart_no); + restart = std::strtoul(restart_no.c_str(), nullptr, 10); handle_RPTSOL_RESTART = true; } } @@ -699,12 +698,9 @@ void RestartConfig::handleScheduleSection(const SCHEDULESection& schedule, const if (found_mnemonic_RESTART == std::string::npos) { if (item.data_size() >= 7) { const std::string& integer_control = item.get< std::string >(6); - try { - restart = boost::lexical_cast(integer_control); + restart = std::strtoul(integer_control.c_str(), nullptr, 10); + if (restart != ULONG_MAX) handle_RPTSOL_RESTART = true; - } catch (boost::bad_lexical_cast &) { - //do nothing - } } } diff --git a/src/opm/parser/eclipse/EclipseState/checkDeck.cpp b/src/opm/parser/eclipse/EclipseState/checkDeck.cpp index 034dcaee9..89ac2e978 100644 --- a/src/opm/parser/eclipse/EclipseState/checkDeck.cpp +++ b/src/opm/parser/eclipse/EclipseState/checkDeck.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace Opm { bool checkDeck( const Deck& deck, const Parser& parser, const ParseContext& parseContext, ErrorGuard& errorGuard, size_t enabledChecks) { @@ -51,10 +52,11 @@ bool checkDeck( const Deck& deck, const Parser& parser, const ParseContext& pars deckValid = deckValid && DeckSection::checkSectionTopology(deck, parser, ensureKeywordSection); } - const std::string& deckUnitSystem = boost::to_upper_copy(deck.getActiveUnitSystem().getName()); + std::string deckUnitSystem = deck.getActiveUnitSystem().getName(); + uppercase(deckUnitSystem); for (const auto& keyword : deck.getKeywordList("FILEUNIT")) { - const std::string& fileUnitSystem = - boost::to_upper_copy(keyword->getRecord(0).getItem("FILE_UNIT_SYSTEM").getTrimmedString(0)); + std::string fileUnitSystem = keyword->getRecord(0).getItem("FILE_UNIT_SYSTEM").getTrimmedString(0); + uppercase(fileUnitSystem); if (fileUnitSystem != deckUnitSystem) { const auto& location = keyword->location(); std::string msg = diff --git a/src/opm/parser/eclipse/Parser/ParseContext.cpp b/src/opm/parser/eclipse/Parser/ParseContext.cpp index 42281a944..118d57e41 100644 --- a/src/opm/parser/eclipse/Parser/ParseContext.cpp +++ b/src/opm/parser/eclipse/Parser/ParseContext.cpp @@ -20,13 +20,12 @@ #include #include -#include - #include #include #include #include +#include namespace Opm { @@ -294,8 +293,7 @@ namespace Opm { */ void ParseContext::update(const std::string& keyString , InputError::Action action) { - std::vector keys; - boost::split( keys , keyString , boost::is_any_of(":|")); + std::vector keys = split_string(keyString, ":|"); for (const auto& input_key : keys) { std::vector matching_keys; size_t wildcard_pos = input_key.find("*"); diff --git a/src/opm/parser/eclipse/Parser/Parser.cpp b/src/opm/parser/eclipse/Parser/Parser.cpp index e4abb4b5c..4b77198a6 100644 --- a/src/opm/parser/eclipse/Parser/Parser.cpp +++ b/src/opm/parser/eclipse/Parser/Parser.cpp @@ -20,8 +20,9 @@ #include #include #include +#include +#include -#include #include #include @@ -535,7 +536,7 @@ Opm::filesystem::path ParserState::getIncludeFilePath( std::string path ) const size_t cutOffPosition = stringStartingAtPathName.find_first_not_of(validPathNameCharacters); std::string stringToFind = stringStartingAtPathName.substr(0, cutOffPosition); std::string stringToReplace = this->pathMap.at( stringToFind ); - boost::replace_all(path, pathKeywordPrefix + stringToFind, stringToReplace); + replaceAll(path, pathKeywordPrefix + stringToFind, stringToReplace); } // Check if there are any backslashes in the path... diff --git a/src/opm/parser/eclipse/Parser/raw/RawKeyword.cpp b/src/opm/parser/eclipse/Parser/raw/RawKeyword.cpp index 405e0da0e..7bc4e86b5 100644 --- a/src/opm/parser/eclipse/Parser/raw/RawKeyword.cpp +++ b/src/opm/parser/eclipse/Parser/raw/RawKeyword.cpp @@ -17,7 +17,6 @@ along with OPM. If not, see . */ #include -#include #include #include @@ -31,7 +30,7 @@ namespace Opm { namespace { std::string keyword_name(const std::string& input_name) { - std::string name = boost::algorithm::trim_right_copy(input_name); + std::string name = rtrim_copy(input_name); if (!ParserKeyword::validDeckName(name)) throw std::invalid_argument("Not a valid keyword:" + name); diff --git a/src/opm/parser/eclipse/RawDeck/RawKeyword.cpp b/src/opm/parser/eclipse/RawDeck/RawKeyword.cpp index 5bc1824e9..1e660cbed 100644 --- a/src/opm/parser/eclipse/RawDeck/RawKeyword.cpp +++ b/src/opm/parser/eclipse/RawDeck/RawKeyword.cpp @@ -17,7 +17,6 @@ along with OPM. If not, see . */ #include -#include #include #include @@ -153,12 +152,12 @@ namespace Opm { } void RawKeyword::setKeywordName(const std::string& name) { - m_name = boost::algorithm::trim_right_copy(name); + m_name = rtrim_copy(name); if (!isValidKeyword(m_name)) { throw std::invalid_argument("Not a valid keyword:" + name); } else if (m_name.size() > Opm::RawConsts::maxKeywordLength) { throw std::invalid_argument("Too long keyword:" + name); - } else if (boost::algorithm::trim_left_copy(m_name) != m_name) { + } else if (ltrim_copy(m_name) != m_name) { throw std::invalid_argument("Illegal whitespace start of keyword:" + name); } } diff --git a/src/opm/parser/eclipse/Units/UnitSystem.cpp b/src/opm/parser/eclipse/Units/UnitSystem.cpp index 73fcc7660..42389b024 100644 --- a/src/opm/parser/eclipse/Units/UnitSystem.cpp +++ b/src/opm/parser/eclipse/Units/UnitSystem.cpp @@ -20,8 +20,8 @@ #include #include -#include +#include #include #include #include @@ -1183,8 +1183,7 @@ namespace { Dimension UnitSystem::parseFactor(const std::string& dimension) const { - std::vector dimensionList; - boost::split(dimensionList , dimension , boost::is_any_of("*")); + std::vector dimensionList = split_string(dimension, '*'); double SIfactor = 1.0; for( const auto& x : dimensionList ) { @@ -1210,8 +1209,7 @@ namespace { const bool haveDivisor = divCount == 1; if( !haveDivisor ) return this->parseFactor( dimension ); - std::vector parts; - boost::split(parts , dimension , boost::is_any_of("/")); + std::vector parts = split_string(dimension, '/'); Dimension dividend = this->parseFactor( parts[0] ); Dimension divisor = this->parseFactor( parts[1] ); diff --git a/tests/parser/InitConfigTest.cpp b/tests/parser/InitConfigTest.cpp index 93461244c..d0cd1004c 100644 --- a/tests/parser/InitConfigTest.cpp +++ b/tests/parser/InitConfigTest.cpp @@ -29,6 +29,8 @@ #include +#include + using namespace Opm; const std::string& deckStr = diff --git a/tests/parser/ParseContext_EXIT1.cpp b/tests/parser/ParseContext_EXIT1.cpp index 5aa8a35c3..6b3d5eafb 100644 --- a/tests/parser/ParseContext_EXIT1.cpp +++ b/tests/parser/ParseContext_EXIT1.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/tests/parser/ParserIncludeTests.cpp b/tests/parser/ParserIncludeTests.cpp index c7a19ad53..a1a1293fa 100644 --- a/tests/parser/ParserIncludeTests.cpp +++ b/tests/parser/ParserIncludeTests.cpp @@ -27,6 +27,8 @@ #include #include +#include + inline std::string prefix() { return boost::unit_test::framework::master_test_suite().argv[1]; } diff --git a/tests/parser/ParserTests.cpp b/tests/parser/ParserTests.cpp index 48313d57d..d02e8ccb5 100644 --- a/tests/parser/ParserTests.cpp +++ b/tests/parser/ParserTests.cpp @@ -35,6 +35,8 @@ #include "src/opm/parser/eclipse/Parser/raw/RawKeyword.hpp" #include "src/opm/parser/eclipse/Parser/raw/RawRecord.hpp" +#include + using namespace Opm; namespace { diff --git a/tests/parser/StringTests.cpp b/tests/parser/StringTests.cpp index 50978ab2e..de7af7b5b 100644 --- a/tests/parser/StringTests.cpp +++ b/tests/parser/StringTests.cpp @@ -213,3 +213,32 @@ BOOST_AUTO_TEST_CASE(trim) { BOOST_CHECK_EQUAL(rtrim_copy(s5) , s5); BOOST_CHECK_EQUAL(rtrim_copy(s6) , s5); } + + +BOOST_AUTO_TEST_CASE(replace_all) { + std::string s1 = "lorem ipsum"; + + replaceAll(s1, "m", "foo"); + BOOST_CHECK_EQUAL(s1, "lorefoo ipsufoo"); +} + + +BOOST_AUTO_TEST_CASE(split) { + std::string s1 = "lorem ipsum"; + + auto split1 = split_string(s1, ' '); + BOOST_CHECK_EQUAL(split1.size(), 2); + BOOST_CHECK_EQUAL(split1[0], "lorem"); + BOOST_CHECK_EQUAL(split1[1], "ipsum"); + + auto split2 = split_string(s1, "r "); + BOOST_CHECK_EQUAL(split2.size(), 3); + BOOST_CHECK_EQUAL(split2[0], "lo"); + BOOST_CHECK_EQUAL(split2[1], "em"); + BOOST_CHECK_EQUAL(split2[2], "ipsum"); + + auto split3 = split_string(s1, "m "); + BOOST_CHECK_EQUAL(split3.size(), 2); + BOOST_CHECK_EQUAL(split3[0], "lore"); + BOOST_CHECK_EQUAL(split3[1], "ipsu"); +} diff --git a/tests/parser/integration/IncludeTest.cpp b/tests/parser/integration/IncludeTest.cpp index 51c23c19e..61c88f32b 100644 --- a/tests/parser/integration/IncludeTest.cpp +++ b/tests/parser/integration/IncludeTest.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include diff --git a/tests/parser/integration/parse_write.cpp b/tests/parser/integration/parse_write.cpp index 247f2913a..ceb5199d9 100644 --- a/tests/parser/integration/parse_write.cpp +++ b/tests/parser/integration/parse_write.cpp @@ -17,6 +17,7 @@ along with OPM. If not, see . */ +#include #include #include