Skip to content

Commit

Permalink
Wrap uses of boost::algorithm
Browse files Browse the repository at this point in the history
These changes allow to more easily replace the use of
Boost capabilities, by wrapping otherwise scattered and direct uses
of boost::join/replace_first/split/starts_with/trim.

Re ECFLOW-1922
  • Loading branch information
marcosbento committed Nov 17, 2023
1 parent 9e170cd commit e39fc77
Show file tree
Hide file tree
Showing 30 changed files with 76 additions and 174 deletions.
6 changes: 2 additions & 4 deletions ACore/src/NodePath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

#include "NodePath.hpp"

#include <boost/algorithm/string/trim.hpp>

#include "Str.hpp"

using namespace ecf;
Expand Down Expand Up @@ -45,8 +43,8 @@ bool NodePath::extractHostPort(const std::string& path, std::string& host, std::
host = thePath[0].substr(0, colonPos);
port = thePath[0].substr(colonPos + 1);

boost::algorithm::trim(host);
boost::algorithm::trim(port);
ecf::algorithm::trim(host);
ecf::algorithm::trim(port);
if (host.empty())
return false;
if (port.empty())
Expand Down
4 changes: 1 addition & 3 deletions ACore/src/PasswdFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include <iostream>

#include <boost/algorithm/string/trim.hpp>

#include "Converter.hpp"
#include "File.hpp"
#include "PasswordEncryption.hpp"
Expand Down Expand Up @@ -73,7 +71,7 @@ bool PasswdFile::load(const std::string& file, bool debug, std::string& errorMsg
theLine.erase(comment_pos);
}

boost::algorithm::trim(theLine); // remove leading and trailing spaces
ecf::algorithm::trim(theLine); // remove leading and trailing spaces
std::vector<std::string> lineTokens;
Str::split(theLine, lineTokens);
if (lineTokens.empty())
Expand Down
29 changes: 29 additions & 0 deletions ACore/src/Str.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,35 @@

namespace ecf {

namespace algorithm {

template <typename Sequence1, typename Sequence2>
inline static auto join(const Sequence1& strings, const Sequence2& separator) {
return ::boost::algorithm::join(strings, separator);
}

template <typename Sequence, typename SearchSequence, typename ReplaceSequence>
inline static auto replace_first(Sequence& input, const SearchSequence& search, const ReplaceSequence& replace) {
return ::boost::algorithm::replace_first(input, search, replace);
}

template <typename ResultSequence, typename Sequence1, typename Sequence2>
inline static ResultSequence& split(ResultSequence& result, const Sequence1& input, const Sequence2& separators) {
return ::boost::algorithm::split(result, input, ::boost::is_any_of(separators));
}

template <typename Sequence1, typename Sequence2>
inline static bool starts_with(const Sequence1& input, const Sequence2& pattern) {
return ::boost::algorithm::starts_with(input, pattern);
}

template <typename Sequence>
inline static void trim(Sequence& input) {
::boost::algorithm::trim(input);
}

} // namespace algorithm

class Str {
public:
static int reserve_4() { return 4; }
Expand Down
4 changes: 1 addition & 3 deletions ACore/src/WhiteListFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <iostream>
#include <vector>

#include <boost/algorithm/string/trim.hpp>

#include "Converter.hpp"
#include "File.hpp"
#include "Str.hpp"
Expand Down Expand Up @@ -257,7 +255,7 @@ bool WhiteListFile::load(const std::string& file, bool debug, std::string& error
theLine.erase(comment_pos);
}

boost::algorithm::trim(theLine); // remove leading and trailing spaces
ecf::algorithm::trim(theLine); // remove leading and trailing spaces
std::vector<std::string> lineTokens;
Str::split(theLine, lineTokens);
if (lineTokens.empty())
Expand Down
7 changes: 3 additions & 4 deletions ANattr/src/CronAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <sstream>
#include <stdexcept>

#include <boost/algorithm/string/trim.hpp>
#include <boost/date_time/posix_time/time_formatters.hpp> // requires boost date and time lib
#include <boost/token_functions.hpp>
#include <boost/tokenizer.hpp>
Expand Down Expand Up @@ -668,7 +667,7 @@ std::vector<int> extract_month(size_t& index, const std::vector<std::string>& li

for (tokenizer::iterator beg = theTokenizer.begin(); beg != theTokenizer.end(); ++beg) {
string theIntToken = *beg;
boost::algorithm::trim(theIntToken);
ecf::algorithm::trim(theIntToken);
if (theIntToken.empty())
continue;

Expand Down Expand Up @@ -704,7 +703,7 @@ void extract_days_of_week(size_t& index,

for (tokenizer::iterator beg = theTokenizer.begin(); beg != theTokenizer.end(); ++beg) {
string theIntToken = *beg;
boost::algorithm::trim(theIntToken);
ecf::algorithm::trim(theIntToken);
if (theIntToken.empty())
continue;

Expand Down Expand Up @@ -751,7 +750,7 @@ void extract_days_of_month(size_t& index,

for (tokenizer::iterator beg = theTokenizer.begin(); beg != theTokenizer.end(); ++beg) {
string theIntToken = *beg;
boost::algorithm::trim(theIntToken);
ecf::algorithm::trim(theIntToken);
if (theIntToken.empty())
continue;

Expand Down
4 changes: 1 addition & 3 deletions ANode/parser/src/DefsStructureParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include <sstream>

#include <boost/algorithm/string/trim.hpp>
#include <boost/token_functions.hpp>
#include <boost/tokenizer.hpp>

#include "Defs.hpp"
Expand Down Expand Up @@ -270,7 +268,7 @@ bool DefsStructureParser::semiColonInEditVariable() {
// edit A fred; edit B bill # valid
// edit A 'fred;bill'; edit B 'bill;bill' # Can't cope with this, will be ONE variable !!!!
for (auto& i : multi_statements_per_line_vec_) {
boost::algorithm::trim(i);
ecf::algorithm::trim(i);
if (i.find("edit") != 0) {
return true;
}
Expand Down
5 changes: 2 additions & 3 deletions ANode/src/EcfFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <sstream>
#include <stdexcept>

#include <boost/algorithm/string/trim.hpp>
#include <boost/filesystem/operations.hpp>
#include <sys/stat.h>
#include <sys/wait.h> // for waitpid
Expand Down Expand Up @@ -434,8 +433,8 @@ void EcfFile::extract_used_variables(NameValueMap& used_variables_as_map,
continue;
string name = script_lines[i].substr(0, equal_pos);
string value = script_lines[i].substr(equal_pos + 1);
boost::algorithm::trim(name);
boost::algorithm::trim(value);
ecf::algorithm::trim(name);
ecf::algorithm::trim(value);

// std::cout << " extracted as '" << name << "' = '" << value << "'\n";
used_variables_as_map.insert(std::make_pair(name, value));
Expand Down
29 changes: 13 additions & 16 deletions ANode/src/ExprParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
#include <sstream>
#include <stack>
#include <string>
#include <utility>

#include <boost/algorithm/string/trim.hpp>
#include <boost/cast.hpp>
#include <boost/spirit/include/classic.hpp>
#include <boost/spirit/include/classic_actor.hpp>
#include <boost/spirit/include/classic_ast.hpp>
Expand Down Expand Up @@ -715,7 +712,7 @@ Ast* createAst(const tree_iter_t& i, const std::map<parser_id, std::string>& rul
if (i->value.id() == ExpressionGrammer::node_name_ID) {

string thevalue(i->value.begin(), i->value.end());
boost::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
LOG_ASSERT(!thevalue.empty(), "");
return new AstNode(thevalue);
}
Expand All @@ -730,8 +727,8 @@ Ast* createAst(const tree_iter_t& i, const std::map<parser_id, std::string>& rul

string nodePath(theNodePathIter->value.begin(), theNodePathIter->value.end());
string name(theNameIter->value.begin(), theNameIter->value.end());
boost::algorithm::trim(nodePath); // don't know why we get leading/trailing spaces
boost::algorithm::trim(name); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(nodePath); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(name); // don't know why we get leading/trailing spaces
return new AstVariable(nodePath, name);
}
else if (i->value.id() == ExpressionGrammer::parent_variable_ID) {
Expand All @@ -740,35 +737,35 @@ Ast* createAst(const tree_iter_t& i, const std::map<parser_id, std::string>& rul
auto the_variable_t = i->children.begin() + 1;

string the_variable(the_variable_t->value.begin(), the_variable_t->value.end());
boost::algorithm::trim(the_variable); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(the_variable); // don't know why we get leading/trailing spaces
LOG_ASSERT(!the_variable.empty(), "");
return new AstParentVariable(the_variable);
}
else if (i->value.id() == ExpressionGrammer::dot_dot_path_ID) {

string thevalue(i->value.begin(), i->value.end());
boost::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
LOG_ASSERT(!thevalue.empty(), "");
return new AstNode(thevalue);
}
if (i->value.id() == ExpressionGrammer::absolute_path_ID) {

string thevalue(i->value.begin(), i->value.end());
boost::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
LOG_ASSERT(!thevalue.empty(), "");
return new AstNode(thevalue);
}
else if (i->value.id() == ExpressionGrammer::dot_path_ID) {

string thevalue(i->value.begin(), i->value.end());
boost::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
LOG_ASSERT(!thevalue.empty(), "");
return new AstNode(thevalue);
}
else if (i->value.id() == ExpressionGrammer::event_state_ID) {

string thevalue(i->value.begin(), i->value.end());
boost::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
if (thevalue == Event::SET())
return new AstEventState(true);
assert(thevalue == Event::CLEAR());
Expand All @@ -777,7 +774,7 @@ Ast* createAst(const tree_iter_t& i, const std::map<parser_id, std::string>& rul
else if (i->value.id() == ExpressionGrammer::integer_ID) {

string thevalue(i->value.begin(), i->value.end());
boost::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(thevalue); // don't know why we get leading/trailing spaces
auto theInt = ecf::convert_to<int>(thevalue);
return new AstInteger(theInt);
}
Expand Down Expand Up @@ -821,8 +818,8 @@ Ast* createAst(const tree_iter_t& i, const std::map<parser_id, std::string>& rul

string nodePath(theNodePathIter->value.begin(), theNodePathIter->value.end());
string flag(theFlagIter->value.begin(), theFlagIter->value.end());
boost::algorithm::trim(nodePath); // don't know why we get leading/trailing spaces
boost::algorithm::trim(flag); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(nodePath); // don't know why we get leading/trailing spaces
ecf::algorithm::trim(flag); // don't know why we get leading/trailing spaces

return new AstFlag(nodePath, ecf::Flag::string_to_flag_type(flag));
}
Expand Down Expand Up @@ -1135,8 +1132,8 @@ bool SimpleExprParser::doParse() {

if (tokens.size() == 2) {

boost::algorithm::trim(tokens[0]);
boost::algorithm::trim(tokens[1]);
ecf::algorithm::trim(tokens[0]);
ecf::algorithm::trim(tokens[1]);

if (tokens[0].find(' ') != string::npos) {
// cout << "Found space " << expr_ << "\n";
Expand Down
4 changes: 2 additions & 2 deletions Base/src/ClientOptionsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "ClientOptionsParser.hpp"

#include <boost/algorithm/string.hpp>
#include "Str.hpp"

namespace ecf {

Expand All @@ -36,7 +36,7 @@ ClientOptionsParser::option_set_t ClientOptionsParser::operator()(ClientOptionsP
// 1) --alter arg1 arg2 arg3 (arg4) path [path [path [...]]]
// 2) --alter=arg1 arg2 arg3 (arg4) path [path [path [...]]]

if (boost::algorithm::starts_with(args[0], "--alter")) {
if (ecf::algorithm::starts_with(args[0], "--alter")) {

option_t alter{std::string{"alter"}, {}};

Expand Down
4 changes: 1 addition & 3 deletions Base/src/cts/GroupCTSCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include <memory>
#include <stdexcept>

#include <boost/algorithm/string/trim.hpp>

#include "AbstractClientEnv.hpp"
#include "AbstractServer.hpp"
#include "ClientOptionsParser.hpp"
Expand Down Expand Up @@ -60,7 +58,7 @@ GroupCTSCmd::GroupCTSCmd(const std::string& cmdSeries, AbstractClientEnv* client
for (auto aCmd : individualCmdVec) {
// massage the commands so that, we add -- at the start of each command.
// This is required by the boost program options.
boost::algorithm::trim(aCmd);
ecf::algorithm::trim(aCmd);

subCmd.clear();
if (aCmd.find("--") == std::string::npos)
Expand Down
7 changes: 2 additions & 5 deletions Base/src/cts/LogCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

#include <stdexcept>

#include <boost/algorithm/string/trim.hpp>

#include "AbstractClientEnv.hpp"
#include "AbstractServer.hpp"
#include "ClientToServerCmd.hpp"
Expand All @@ -28,7 +26,6 @@

using namespace ecf;
using namespace std;
using namespace boost;
namespace po = boost::program_options;

LogCmd::LogCmd(LogApi a, int get_last_n_lines) : api_(a), get_last_n_lines_(get_last_n_lines) {
Expand All @@ -48,7 +45,7 @@ LogCmd::LogCmd(const std::string& path)
// ECFLOW-174, Never get the full log, as this can make server consume to much memory
// default taken from get_last_n_lines_default
// ECFLOW-377, should remove leading/trailing spaces from path
boost::algorithm::trim(new_path_);
ecf::algorithm::trim(new_path_);
}

void LogCmd::print(std::string& os) const {
Expand Down Expand Up @@ -159,7 +156,7 @@ STC_Cmd_ptr LogCmd::doHandleRequest(AbstractServer* as) const {
std::string log_file_name = as->defs()->server().find_variable(Str::ECF_LOG());

// ECFLOW-377 should remove leading/trailing spaces from path
boost::algorithm::trim(log_file_name);
ecf::algorithm::trim(log_file_name);

Log::instance()->new_path(log_file_name); // will throw for errors
}
Expand Down
1 change: 0 additions & 1 deletion Pyext/src/ExportClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <algorithm> // for std::transform

#include <boost/algorithm/string.hpp>
#include <boost/core/noncopyable.hpp>
#include <boost/python.hpp>

Expand Down
7 changes: 3 additions & 4 deletions Viewer/ecflowUI/src/EditProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

#include "EditProvider.hpp"

#include <boost/algorithm/string.hpp>

#include "NodeFwd.hpp"
#include "ServerHandler.hpp"
#include "Str.hpp"
#include "UiLog.hpp"
#include "VNode.hpp"
#include "VReply.hpp"
Expand Down Expand Up @@ -85,8 +84,8 @@ void EditProvider::submit(const std::vector<std::string>& txt, bool alias) {
if (pos != std::string::npos && pos + 1 != it.size()) {
std::string name = it.substr(0, pos);
std::string val = it.substr(pos + 1);
boost::trim(name);
boost::trim(val);
ecf::algorithm::trim(name);
ecf::algorithm::trim(val);
vars.push_back(std::make_pair(name, val));
}
}
Expand Down
5 changes: 2 additions & 3 deletions Viewer/ecflowUI/src/ExpandState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

#include "ExpandState.hpp"

#include <boost/algorithm/string.hpp>

#include "AbstractNodeView.hpp"
#include "ExpandStateNode.hpp"
#include "ServerHandler.hpp"
#include "Str.hpp"
#include "TreeNodeModel.hpp"
#include "UIDebug.hpp"
#include "UiLog.hpp"
Expand Down Expand Up @@ -288,7 +287,7 @@ ExpandStateNode* ExpandState::find(const std::string& fullPath) {
return root_;

std::vector<std::string> pathVec;
boost::split(pathVec, fullPath, boost::is_any_of("/"));
ecf::algorithm::split(pathVec, fullPath, "/");

if (pathVec.size() > 0 && pathVec[0].empty()) {
pathVec.erase(pathVec.begin());
Expand Down
1 change: 0 additions & 1 deletion Viewer/ecflowUI/src/InfoProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <stdexcept>

#include <QDateTime>
#include <boost/algorithm/string/predicate.hpp>

#include "EcfFile.hpp"
#include "ServerHandler.hpp"
Expand Down
Loading

0 comments on commit e39fc77

Please sign in to comment.