12 #ifndef ZYPP_BASE_STRINGV_H
13 #define ZYPP_BASE_STRINGV_H
14 #include <string_view>
15 #ifdef __cpp_lib_string_view
26 using regex = str::regex;
27 using smatch = str::smatch;
43 using WordConsumer = std::function<bool(std::string_view,
unsigned,
bool)>;
60 template <
typename Callable, std::enable_if_t<
61 std::is_invocable_r_v<bool,Callable,std::string_view,unsigned,bool>
63 WordConsumer wordConsumer( Callable && fnc_r )
64 {
return std::forward<Callable>(fnc_r); }
66 template <
typename Callable, std::enable_if_t<
67 ! std::is_invocable_r_v<bool,Callable,std::string_view,unsigned,bool>
68 && std::is_invocable_r_v<void,Callable,std::string_view,unsigned,bool>
70 WordConsumer wordConsumer( Callable && fnc_r )
71 {
return [&fnc_r](std::string_view a1,
unsigned a2,
bool a3)->
bool { fnc_r(a1,a2,a3);
return true; }; }
74 template <
typename Callable, std::enable_if_t<
75 std::is_invocable_r_v<bool,Callable,std::string_view,unsigned>
77 WordConsumer wordConsumer( Callable && fnc_r )
78 {
return [&fnc_r](std::string_view a1,
unsigned a2,bool)->
bool {
return fnc_r(a1,a2); }; }
80 template <
typename Callable, std::enable_if_t<
81 ! std::is_invocable_r_v<bool,Callable,std::string_view,unsigned>
82 && std::is_invocable_r_v<void,Callable,std::string_view,unsigned>
84 WordConsumer wordConsumer( Callable && fnc_r )
85 {
return [&fnc_r](std::string_view a1,
unsigned a2,bool)->
bool { fnc_r(a1,a2);
return true; }; }
88 template <
typename Callable, std::enable_if_t<
89 std::is_invocable_r_v<bool,Callable,std::string_view>
91 WordConsumer wordConsumer( Callable && fnc_r )
92 {
return [&fnc_r](std::string_view a1,unsigned,bool)->
bool {
return fnc_r(a1); }; }
94 template <
typename Callable, std::enable_if_t<
95 ! std::is_invocable_r_v<bool,Callable,std::string_view>
96 && std::is_invocable_r_v<void,Callable,std::string_view>
98 WordConsumer wordConsumer( Callable && fnc_r )
99 {
return [&fnc_r](std::string_view a1,unsigned,bool)->
bool { fnc_r(a1);
return true; }; }
102 template <
typename Callable, std::enable_if_t<
103 std::is_invocable_r_v<bool,Callable>
105 WordConsumer wordConsumer( Callable && fnc_r )
106 {
return [&fnc_r](std::string_view,unsigned,bool)->
bool {
return fnc_r(); }; }
108 template <
typename Callable, std::enable_if_t<
109 ! std::is_invocable_r_v<bool,Callable>
110 && std::is_invocable_r_v<void,Callable>
112 WordConsumer wordConsumer( Callable && fnc_r )
113 {
return [&fnc_r](std::string_view,unsigned,bool)->
bool { fnc_r();
return true; }; }
117 unsigned _splitRx(
const std::string & line_r,
const regex & rx_r, WordConsumer && fnc_r );
141 template <
typename Callable = detail::WordConsumer>
142 unsigned splitRx(
const std::string & line_r,
const regex & rx_r, Callable && fnc_r = Callable() )
143 {
return detail::_splitRx( line_r, rx_r, detail::wordConsumer( std::forward<Callable>(fnc_r) ) ); }
195 unsigned split( std::string_view line_r, std::string_view sep_r,
Trim trim_r,
196 std::function<
void(std::string_view)> fnc_r );
199 inline unsigned split( std::string_view line_r, std::string_view sep_r,
200 std::function<
void(std::string_view)> fnc_r )
201 {
return split( line_r, sep_r, Trim::notrim, fnc_r ); }
204 inline unsigned split( std::string_view line_r,
205 std::function<
void(std::string_view)> fnc_r )
206 {
return split( line_r, std::string_view(), Trim::notrim, fnc_r ); }
#define ZYPP_DECLARE_FLAGS_AND_OPERATORS(Name, Enum)
Trim
To define how to trim.
std::string trim(const std::string &s, const Trim trim_r)
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.