12#include <zypp-core/base/StringV.h>
26 unsigned _splitSimple( std::string_view line_r, WordConsumer && fnc_r )
32 const char *
const eol = line_r.data() + line_r.size();
33 const char * searchfrom = line_r.data();
36 auto isSep = [](
char ch )->
bool {
return ch ==
' '|| ch ==
'\t'; };
38 auto skipSep = [eol,&isSep](
const char *& ptr )->
bool {
39 while ( ptr < eol && isSep( *ptr ) )
44 auto skipWord = [eol,&isSep](
const char *& ptr )->
void {
45 while ( ptr < eol && ! isSep( *ptr ) )
51 std::string_view word;
53 while ( skipSep( searchfrom ) ) {
54 const char * wordstart = searchfrom;
56 if ( ! word.empty() ) {
58 if ( ! fnc_r( word, fncCall,
false ) ) {
61 const char * wordend = eol;
62 while ( isSep( *(wordend-1) ) )
64 word = std::string_view( wordstart, wordend-wordstart );
73 skipWord( searchfrom );
74 word = std::string_view( wordstart, searchfrom-wordstart );
78 if ( ! word.empty() ) {
80 fnc_r( word, fncCall,
true );
89 unsigned detail::_split( std::string_view line_r, std::string_view sep_r, Trim trim_r, WordConsumer && fnc_r )
92 return _splitSimple( line_r, std::move( fnc_r ) );
98 using size_type = std::string_view::size_type;
99 size_type wordstart = 0;
100 size_type searchfrom = 0;
103 searchfrom = line_r.find( sep_r, searchfrom );
104 if ( fncStop || searchfrom == line_r.npos ) {
110 if ( ! fnc_r( trim( line_r.substr(wordstart,searchfrom-wordstart), trim_r ), fncCall,
false ) )
116 searchfrom += sep_r.size();
117 wordstart = searchfrom;
118 }
while( wordstart < line_r.size() );
122 if ( wordstart < line_r.size() )
123 fnc_r(
trim( line_r.substr(wordstart,line_r.size()-wordstart), trim_r ), fncCall,
true );
125 fnc_r( std::string_view( line_r.data()+line_r.size(), 0 ), fncCall,
true );
132 unsigned detail::_splitRx(
const std::string & line_r,
const regex & rx_r, WordConsumer && fnc_r )
133 {
return _splitRx( std::string_view(line_r), rx_r, std::move(fnc_r) ); }
135 unsigned detail::_splitRx( std::string_view line_r,
const regex & rx_r, WordConsumer && fnc_r )
138 bool fncStop =
false;
139 unsigned fncCall = 0;
142 const char *
const eol = line_r.data() + line_r.size();
143 bool trailingNL = line_r.size() && *(eol-1) ==
'\n';
144 const char * wordstart = line_r.data();
145 const char * searchfrom = line_r.data();
148 auto matchAtBOL = [&]() {
149 return searchfrom == line_r.data() || *(searchfrom-1) ==
'\n' ? regex::none : regex::not_bol;
153 if ( fncStop || ! rx_r.matches( searchfrom, match, matchAtBOL() ) ) {
156 if ( trailingNL && searchfrom+match.begin(0) == eol )
159 if ( match.end(0) == 0 && searchfrom == wordstart && searchfrom != line_r.data() ) {
168 if ( ! fnc_r( std::string_view( wordstart, searchfrom+match.begin(0) - wordstart ), fncCall,
false ) )
174 wordstart = searchfrom+match.end(0);
175 searchfrom += match.end(0) ? match.end(0) : 1;
177 }
while ( searchfrom <= eol );
181 if ( wordstart < eol )
182 fnc_r( std::string_view( wordstart, eol-wordstart ), fncCall,
true );
184 fnc_r( std::string_view( eol, 0 ), fncCall,
true );
std::string trim(const std::string &s, const Trim trim_r)
unsigned _splitSimple(std::string_view line_r, WordConsumer &&fnc_r)
split working horse for empty sep_r case.
Easy-to use interface to the ZYPP dependency resolver.