12#ifndef ZYPP_BASE_STRINGV_H 
   13#define ZYPP_BASE_STRINGV_H 
   15#ifdef __cpp_lib_string_view 
   27    using regex = str::regex;
 
   28    using smatch = str::smatch;
 
   41    inline constexpr std::string_view blank = 
" \t";
 
   44    inline std::string_view 
ltrim( std::string_view str_r, std::string_view chars_r = blank )
 
   48      auto pos = str_r.find_first_not_of( chars_r );
 
   49      if ( pos == str_r.npos )
 
   50        str_r.remove_prefix( str_r.size() );
 
   52        str_r.remove_prefix( pos );
 
   57    inline std::string_view 
rtrim( std::string_view str_r, std::string_view chars_r = blank )
 
   61      auto pos = str_r.find_last_not_of( chars_r );
 
   62      if ( pos == str_r.npos )
 
   63        str_r.remove_suffix( str_r.size() );
 
   64      else if ( (pos = str_r.size()-1-pos) )
 
   65        str_r.remove_suffix( pos );
 
   70    inline std::string_view 
trim( std::string_view str_r, std::string_view chars_r = blank )
 
   74      str_r = 
ltrim( std::move(str_r), chars_r );
 
   75      str_r = 
rtrim( std::move(str_r), chars_r );
 
   80    inline std::string_view 
trim( std::string_view str_r, std::string_view chars_r, TrimFlag trim_r )
 
   82      if ( str_r.empty() || trim_r == Trim::notrim )
 
   84      if ( trim_r.testFlag( Trim::left ) )
 
   85        str_r = 
ltrim( std::move(str_r), chars_r );
 
   86      if ( trim_r.testFlag( Trim::right ) )
 
   87        str_r = 
rtrim( std::move(str_r), chars_r );
 
   91    inline std::string_view 
trim( std::string_view str_r, TrimFlag trim_r )
 
   92    { 
return trim( std::move(str_r), blank, std::move(trim_r) ); }
 
   95    inline bool hasPrefix( std::string_view str_r, std::string_view prefix_r )
 
   96    { 
return( ::strncmp( str_r.data(), prefix_r.data(), prefix_r.size() ) == 0 ); }
 
   99    inline bool hasPrefixCI( std::string_view str_r, std::string_view prefix_r  )
 
  100    { 
return( ::strncasecmp( str_r.data(), prefix_r.data(), prefix_r.size()  ) == 0 ); }
 
  106      using WordConsumer = std::function<bool(std::string_view,
unsigned,
bool)>;
 
  124      std::is_invocable_r_v<bool,Callable,std::string_view,unsigned,bool>
 
  126      WordConsumer wordConsumer( Callable && fnc_r )
 
  127      { 
return std::forward<Callable>(fnc_r); }
 
  130      ! std::is_invocable_r_v<bool,Callable,std::string_view,unsigned,bool>
 
  131      && std::is_invocable_r_v<void,Callable,std::string_view,unsigned,bool>
 
  133      WordConsumer wordConsumer( Callable && fnc_r )
 
  134      { 
return [&fnc_r](std::string_view a1,
unsigned a2,
bool a3)->
bool { fnc_r(a1,a2,a3); 
return true; }; }
 
  138      std::is_invocable_r_v<bool,Callable,std::string_view,unsigned>
 
  140      WordConsumer wordConsumer( Callable && fnc_r )
 
  141      { 
return [&fnc_r](std::string_view a1,
unsigned a2,bool)->
bool { 
return fnc_r(a1,a2); }; }
 
  144      ! std::is_invocable_r_v<bool,Callable,std::string_view,unsigned>
 
  145      && std::is_invocable_r_v<void,Callable,std::string_view,unsigned>
 
  147      WordConsumer wordConsumer( Callable && fnc_r )
 
  148      { 
return [&fnc_r](std::string_view a1,
unsigned a2,bool)->
bool { fnc_r(a1,a2); 
return true; }; }
 
  152      std::is_invocable_r_v<bool,Callable,std::string_view>
 
  154      WordConsumer wordConsumer( Callable && fnc_r )
 
  155      { 
return [&fnc_r](std::string_view a1,unsigned,bool)->
bool { 
return fnc_r(a1); }; }
 
  158      ! std::is_invocable_r_v<bool,Callable,std::string_view>
 
  159      && std::is_invocable_r_v<void,Callable,std::string_view>
 
  161      WordConsumer wordConsumer( Callable && fnc_r )
 
  162      { 
return [&fnc_r](std::string_view a1,unsigned,bool)->
bool { fnc_r(a1); 
return true; }; }
 
  166      std::is_invocable_r_v<bool,Callable>
 
  168      WordConsumer wordConsumer( Callable && fnc_r )
 
  169      { 
return [&fnc_r](std::string_view,unsigned,bool)->
bool { 
return fnc_r(); }; }
 
  172      ! std::is_invocable_r_v<bool,Callable>
 
  173      && std::is_invocable_r_v<void,Callable>
 
  175      WordConsumer wordConsumer( Callable && fnc_r )
 
  176      { 
return [&fnc_r](std::string_view,unsigned,bool)->
bool { fnc_r(); 
return true; }; }
 
  180      unsigned _split( std::string_view line_r, std::string_view sep_r, Trim trim_r, WordConsumer && fnc_r ) 
ZYPP_API;
 
  183      unsigned _splitRx(std::string_view line_r, 
const regex & rx_r, 
const WordConsumer& fnc_r );
 
  207    template <
typename Callable = detail::WordConsumer>
 
  208    unsigned splitRx( std::string_view line_r, 
const regex & rx_r, Callable && fnc_r = Callable() )
 
  209    { 
return detail::_splitRx( line_r, rx_r, detail::wordConsumer( std::forward<Callable>(fnc_r) ) ); }
 
  272    template <
typename Callable = detail::WordConsumer>
 
  273    unsigned split( std::string_view line_r, std::string_view sep_r, Trim trim_r, Callable && fnc_r = Callable() )
 
  274    { 
return detail::_split( line_r, sep_r, trim_r, detail::wordConsumer( std::forward<Callable>(fnc_r) ) ); }
 
  277    template <
typename Callable = detail::WordConsumer>
 
  278    inline unsigned split( std::string_view line_r, std::string_view sep_r, Callable && fnc_r = Callable() )
 
  279    { 
return detail::_split( line_r, sep_r, Trim::notrim, detail::wordConsumer( std::forward<Callable>(fnc_r) ) ); }
 
  282    template <
typename Callable = detail::WordConsumer>
 
  283    inline unsigned split( std::string_view line_r, Callable && fnc_r = Callable() )
 
  284    { 
return detail::_split( line_r, std::string_view(), Trim::notrim, detail::wordConsumer( std::forward<Callable>(fnc_r) ) ); }
 
  286    inline std::string_view asStringView( 
const char * t )
 
  287    { 
return t == 
nullptr ? std::string_view() : t; }
 
typename enable_if< B, T >::type enable_if_t
Trim
To define how to trim.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
std::string rtrim(const std::string &s)
std::string ltrim(const std::string &s)
bool hasPrefixCI(const C_Str &str_r, const C_Str &prefix_r)
std::string trim(const std::string &s, const Trim trim_r)
void split(ParamVec &pvec, const std::string &pstr, const std::string &psep)
Split into a parameter vector.
Easy-to use interface to the ZYPP dependency resolver.
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Provides API related macros.
#define ZYPP_DECLARE_FLAGS_AND_OPERATORS(Name, Enum)