20 unsigned split( std::string_view line_r, std::string_view sep_r,
Trim trim_r,
21 std::function<
void(std::string_view)> fnc_r )
24 std::vector<std::string> words;
25 str::split( std::string(line_r), std::back_inserter(words), std::string(sep_r),
str::TRIM );
28 for (
const auto & w : words )
29 fnc_r( std::string_view(w) );
35 unsigned detail::_splitRx(
const std::string & line_r,
const regex & rx_r, WordConsumer && fnc_r )
42 const char *
const eol = line_r.data() + line_r.size();
43 bool trailingNL = line_r.size() && *(eol-1) ==
'\n';
44 const char * wordstart = line_r.data();
45 const char * searchfrom = line_r.data();
48 auto matchAtBOL = [&]() {
49 return searchfrom == line_r.data() || *(searchfrom-1) ==
'\n' ? regex::none : regex::not_bol;
53 if ( fncStop || ! rx_r.matches( searchfrom, match, matchAtBOL() ) ) {
56 if ( trailingNL && searchfrom+match.begin(0) == eol )
59 if ( match.end(0) == 0 && searchfrom == wordstart && searchfrom != line_r.data() ) {
68 if ( ! fnc_r( std::string_view( wordstart, searchfrom+match.begin(0) - wordstart ), fncCall,
false ) )
74 wordstart = searchfrom+match.end(0);
75 searchfrom += match.end(0) ? match.end(0) : 1;
77 }
while ( searchfrom <= eol );
81 if ( wordstart < eol )
82 fnc_r( std::string_view( wordstart, eol-wordstart ), fncCall,
true );
84 fnc_r( std::string_view( eol, 0 ), fncCall,
true );
c++17: std::string_view tools
Trim
To define how to trim.
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", const Trim trim_r=NO_TRIM)
Split line_r into words.
unsigned split(std::string_view line_r, std::string_view sep_r, Trim trim_r, std::function< void(std::string_view)> fnc_r)
Easy-to use interface to the ZYPP dependency resolver.