42 std::stringstream ss{};
55 std::stringstream ss{};
65template <
typename ContainerT = std::vector<std::
string>,
66 typename PredicateT = std::function<std::
string(const std::
string&)>>
75 while(_beginp < line.length() && _delimp < line.length())
78 _beginp = line.find_first_not_of(delimiters, _delimp);
81 if(_beginp == std::string::npos)
84 _delimp = line.find_first_of(delimiters, _beginp);
90 _tmp = line.substr(_beginp, _delimp - _beginp);
91 }
catch(std::exception& e)
94 fprintf(stderr,
"%s\n", e.what());
99 _result.insert(_result.end(), predicate(_tmp));
109template <
typename PredicateT = std::function<std::
string(const std::
string&)>>
117 while(_beg_pos < _result.length() && _end_pos < _result.length())
120 _beg_pos = _result.find(_begin, _end_pos);
123 if(_beg_pos == std::string::npos)
128 _end_pos = _result.find(_end, _beg_pos + 1);
130 _end_pos = _beg_pos + _begin.length();
133 if(_end_pos == std::string::npos)
137 auto _len = _end_pos - _beg_pos;
140 auto _sub = _result.substr(_beg_pos, _len);
143 auto _transformed = predicate(_sub);
146 if(_sub != _transformed)
148 _result = _result.replace(_beg_pos, _len, _transformed);
150 _end_pos = _beg_pos + _transformed.length();
std::string str_transform(const std::string &input, const std::string &_begin, const std::string &_end, PredicateT &&predicate)
apply a string transformation to substring inbetween a common delimiter. e.g.
T from_string(const std::string &str)
tim::mpl::apply< std::string > string
ContainerT delimit(const std::string &line, const std::string &delimiters="\"',;: ", PredicateT &&predicate=[](const std::string &s) -> std::string { return s;})