libzypp 17.25.7
StringV.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_BASE_STRINGV_H
13#define ZYPP_BASE_STRINGV_H
14#include <string_view>
15#ifdef __cpp_lib_string_view
16
17#include <zypp/base/String.h>
18#include <zypp/base/Regex.h>
19#include <zypp/base/Flags.h>
20
22namespace zypp
23{
24 namespace strv
25 {
26 using regex = str::regex;
27 using smatch = str::smatch;
28
30 enum class Trim {
31 notrim = 0,
32 right = 1<<0,
33 left = 1<<1,
34 trim = (left|right),
35 };
36
38
40 namespace detail
41 {
43 using WordConsumer = std::function<bool(std::string_view,unsigned,bool)>;
44
60 template <typename Callable, std::enable_if_t<
61 std::is_invocable_r_v<bool,Callable,std::string_view,unsigned,bool>
62 , bool> = true>
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>
69 , bool> = true>
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; }; }
72
74 template <typename Callable, std::enable_if_t<
75 std::is_invocable_r_v<bool,Callable,std::string_view,unsigned>
76 , bool> = true>
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>
83 , bool> = true>
84 WordConsumer wordConsumer( Callable && fnc_r )
85 { return [&fnc_r](std::string_view a1,unsigned a2,bool)->bool { fnc_r(a1,a2); return true; }; }
86
88 template <typename Callable, std::enable_if_t<
89 std::is_invocable_r_v<bool,Callable,std::string_view>
90 , bool> = true>
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>
97 , bool> = true>
98 WordConsumer wordConsumer( Callable && fnc_r )
99 { return [&fnc_r](std::string_view a1,unsigned,bool)->bool { fnc_r(a1); return true; }; }
100
102 template <typename Callable, std::enable_if_t<
103 std::is_invocable_r_v<bool,Callable>
104 , bool> = true>
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>
111 , bool> = true>
112 WordConsumer wordConsumer( Callable && fnc_r )
113 { return [&fnc_r](std::string_view,unsigned,bool)->bool { fnc_r(); return true; }; }
115
117 unsigned _splitRx( const std::string & line_r, const regex & rx_r, WordConsumer && fnc_r );
118 } // namespace detail
120
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) ) ); }
144
145
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 );
197
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 ); }
202
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 ); }
207
208 } // namespace strv
209} // namespace zypp
211#endif // __cpp_lib_string_view
212#endif // ZYPP_BASE_STRINGV_H
#define ZYPP_DECLARE_FLAGS_AND_OPERATORS(Name, Enum)
Definition: Flags.h:189
Trim
To define how to trim.
Definition: String.h:493
std::string trim(const std::string &s, const Trim trim_r)
Definition: String.cc:223
unsigned split(std::string_view line_r, std::string_view sep_r, Trim trim_r, std::function< void(std::string_view)> fnc_r)
Definition: StringV.cc:20
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2