9 #ifndef ZYPP_NG_CORE_STRING_H_INCLUDED 10 #define ZYPP_NG_CORE_STRING_H_INCLUDED 14 #include <boost/utility/string_view.hpp> 26 const int entryVal = zypp::str::strtonum<T>( val.data() );
27 if ( errno == ERANGE )
32 template<
typename StrType,
typename T = std::remove_reference_t<StrType> >
35 T ret( std::forward<StrType>(s) );
42 typename T::size_type p = ret.find_first_not_of(
" \t\r\n" );
45 if constexpr ( std::is_same_v<std::string_view, StrType> )
52 ret.remove_prefix( p );
57 typename T::size_type p = ret.find_last_not_of(
" \t\r\n" );
60 if constexpr ( std::is_same_v<std::string_view, StrType> )
67 ret.remove_suffix( ret.size() - ( p+1 ) );
73 template<
class TOutputIterator>
74 void split(
const boost::string_view & line_r, TOutputIterator result_r,
const boost::string_view & sepchars_r =
" \t",
const Trim trim_r =
Trim::NO_TRIM )
80 if ( tokenBegin == std::string_view::npos )
83 while ( ( tokenEnd = line_r.find_first_of( sepchars_r, tokenBegin ) ) != std::string_view::npos ) {
84 auto line = line_r.substr( tokenBegin, tokenEnd-tokenBegin );
85 *result_r =
trim( line, trim_r );
88 tokenBegin = line_r.find_first_not_of( sepchars_r, tokenEnd );
89 if( tokenBegin == std::string_view::npos )
94 if ( tokenBegin != std::string_view::npos && tokenBegin < line_r.size() )
95 *result_r =
trim( line_r.substr( tokenBegin ), trim_r );
T trim(StrType &&s, const Trim trim_r)
void split(const boost::string_view &line_r, TOutputIterator result_r, const boost::string_view &sepchars_r=" \, const Trim trim_r=Trim::NO_TRIM)
String related utilities and Regular expression matching.
Trim
To define how to trim.
std::optional< T > safe_strtonum(const std::string_view &val)
std::string strerror(int errno_r)
Return string describing the error_r code.