20#include <zypp/base/LogTools.h>
21#include <zypp/base/Gettext.h>
22#include <zypp/base/String.h>
57 case SEARCH_STRING:
return STRING;
break;
59 case SEARCH_STRINGEND:
return STRINGEND;
break;
60 case SEARCH_SUBSTRING:
return SUBSTRING;
break;
61 case SEARCH_GLOB:
return GLOB;
break;
62 case SEARCH_REGEX:
return REGEX;
break;
72 case STRING:
return SEARCH_STRING;
break;
74 case STRINGEND:
return SEARCH_STRINGEND;
break;
75 case SUBSTRING:
return SEARCH_SUBSTRING;
break;
76 case GLOB:
return SEARCH_GLOB;
break;
77 case REGEX:
return SEARCH_REGEX;
break;
78 case OTHER:
return SEARCH_STRINGMASK;
break;
80 return SEARCH_STRINGMASK;
84 { std::ostringstream
str;
str << *
this;
return str.str(); }
90#define OUTS(V) case Match::V: return str << #V; break
101 return str <<
"Match::Mode::UNKNOWN";
107 return str <<
"NOTHING";
109 const char * sep =
"|";
127#define OUTS(V) if ( val & Match::V.get() ) { val &= ~Match::V.get(); if ( sep ) str << sep; else sep = "|"; str << #V; }
129 OUTS( NO_STORAGE_SOLVABLE );
131 OUTS( ARRAYSENTINEL );
132 OUTS( DISABLED_REPOS );
133 OUTS( COMPLETE_FILELIST );
140 if ( sep )
str << sep;
152 :
MatchException( msg_r.empty() ?
str::form(
_(
"Unknown match mode '%s'"), mode_r.asString().c_str() )
153 :
str::form(
_(
"Unknown match mode '%s' for pattern '%s'"), mode_r.asString().c_str(), msg_r.c_str() ) )
157 :
MatchException( regcomp_r ?
str::form(
_(
"Invalid regular expression '%s': regcomp returned %d"), regex_r.c_str(), regcomp_r )
158 :
str::form(
_(
"Invalid regular expression '%s'"), regex_r.c_str() ) )
210 return ::datamatcher_match(
_matcher.get(), string_r );
234 ::datamatcher_free(
_matcher.get() );
241 mutable scoped_ptr< sat::detail::CDatamatcher>
_matcher;
244 friend Impl * rwcowClone<Impl>(
const Impl * rhs );
265 : _pimpl( new
Impl( search_r,
Match::STRING ) )
268 : _pimpl( new
Impl(
std::move(search_r),
Match::STRING ) )
272 : _pimpl( new
Impl( search_r, flags_r ) )
275 : _pimpl( new
Impl(
std::move(search_r), flags_r ) )
279 : _pimpl( new
Impl( search_r, flags_r ) )
282 : _pimpl( new
Impl(
std::move(search_r), flags_r ) )
286 : _pimpl( new
Impl( search_r,
Match(flags_r) ) )
289 : _pimpl( new
Impl(
std::move(search_r),
Match(flags_r) ) )
293 {
return _pimpl->compile(); }
296 {
return _pimpl->isCompiled(); }
299 {
return _pimpl->doMatch( string_r ); }
302 {
return _pimpl->searchstring(); }
305 {
_pimpl->setSearchstring( string_r ); }
307 {
_pimpl->setSearchstring( std::move(string_r) ); }
311 _pimpl->setSearchstring( string_r );
312 _pimpl->setFlags( flags_r );
316 _pimpl->setSearchstring( std::move(string_r) );
317 _pimpl->setFlags( flags_r );
321 {
return _pimpl->flags(); }
324 {
_pimpl->setFlags( flags_r ); }
String matching option flags as used e.g.
static const Match DISABLED_REPOS
LookupAttr: internal.
int flagval() const
Return the flags integer representation.
int get() const
Return the integer representation.
std::string asString() const
String representation.
static const Match ARRAYSENTINEL
LookupAttr: internal.
static const Match SUB
LookupAttr: internal.
Mode
Mode flags (mutual exclusive).
@ STRINGEND
Match at string end.
@ REGEX
Regular Expression.
@ STRINGSTART
Match at string start.
@ SUBSTRING
Match substring.
static const Match COMPLETE_FILELIST
LookupAttr: internal.
static const Match CHECKSUMS
LookupAttr: also look for matches in checksums.
static const int _flagmask
static const Match NO_STORAGE_SOLVABLE
LookupAttr: internal.
static const Match FILES
LookupAttr: match full path when matching in filelists, otherwise just the basenames.
static const Match SKIP_KIND
LookupAttr: skip any kind: prefix when looking at a Solvable name.
static const Match NOCASE
If set, match case insensitive.
int modeval() const
Return the modes integer representation.
static const int _modemask
Mode mode() const
Return the mode part.
String matching (STRING|SUBSTRING|GLOB|REGEX).
bool doMatch(const char *string_r) const
Return whether string matches.
const std::string & searchstring() const
The current searchstring.
const Match & flags() const
The current search flags.
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
StrMatcher()
Default ctor matches nothing.
void setSearchstring(const std::string &string_r)
Set a new searchstring.
void setFlags(const Match &flags_r)
Set new search flags.
bool isCompiled() const
Whether the StrMatcher is already compiled.
void compile() const
Compile the pattern e.g.
String related utilities and Regular expression matching.
::s_Datamatcher CDatamatcher
Wrapped libsolv C data type exposed as backdoor.
std::string hexstring(char n, int w=4)
Easy-to use interface to the ZYPP dependency resolver.
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Exceptions thrown from attribute matching.
Invalid regular expression (failed ::regcomp).
MatchInvalidRegexException(const std::string &msg_r)
Supplied message.
MatchUnknownModeException(const std::string &msg_r)
Supplied message.
StrMatcher implementation.
Impl * clone() const
clone for RWCOW_pointer
const Match & flags() const
The current search flags.
const std::string & searchstring() const
The current searchstring.
void compile() const
Compile the pattern.
bool isCompiled() const
Whether the pattern is already compiled.
bool doMatch(const char *string_r) const
Return whether string matches.
void invalidate()
Has to be called if _search or _flags change.
void setSearchstring(std::string string_r)
Set a new searchstring.
std::ostream & operator<<(std::ostream &str, const StrMatcher::Impl &obj)
Stream output.
Impl(std::string search_r, const Match &flags_r)
void setFlags(const Match &flags_r)
Set new search flags.
scoped_ptr< sat::detail::CDatamatcher > _matcher
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.