libzypp  17.3.1
zypp::StrMatcher Class Reference

String matching (STRING|SUBSTRING|GLOB|REGEX). More...

#include <StrMatcher.h>

Classes

class  Impl
 StrMatcher implementation. More...
 

Public Types

typedef MatchException Exception
 

Public Member Functions

 StrMatcher ()
 Default ctor matches nothing. More...
 
 StrMatcher (const std::string &search_r)
 Ctor from string matches in Match::STRING mode per default. More...
 
 StrMatcher (std::string &&search_r)
 
 StrMatcher (const std::string &search_r, const Match &flags_r)
 Ctor taking string and Match flags. More...
 
 StrMatcher (std::string &&search_r, const Match &flags_r)
 
 StrMatcher (const std::string &search_r, const Match::Mode &flags_r)
 Ctor taking string and Match::Mode. More...
 
 StrMatcher (std::string &&search_r, const Match::Mode &flags_r)
 
 StrMatcher (const std::string &search_r, int flags_r)
 Low level interface wraps flags into Match. More...
 
 StrMatcher (std::string &&search_r, int flags_r)
 
 operator bool () const
 Evaluate in a boolean context ( ! searchstring().empty() ). More...
 
template<class Tp >
bool operator() (const Tp &string_r) const
 Return whether string matches. More...
 
bool operator() (const char *string_r) const
 
const std::string & searchstring () const
 The current searchstring. More...
 
void setSearchstring (const std::string &string_r)
 Set a new searchstring. More...
 
void setSearchstring (std::string &&string_r)
 
void setSearchstring (const std::string &string_r, const Match &flags_r)
 Set a new searchstring and flags. More...
 
void setSearchstring (std::string &&string_r, const Match &flags_r)
 
const Matchflags () const
 The current search flags. More...
 
void setFlags (const Match &flags_r)
 Set new search flags. More...
 
void compile () const
 Compile the pattern e.g. More...
 
bool isCompiled () const
 Whether the StrMatcher is already compiled. More...
 
bool doMatch (const char *string_r) const
 Return whether string matches. More...
 

Private Attributes

RWCOW_pointer< Impl_pimpl
 Pointer to implementation. More...
 

Friends

std::ostream & operator<< (std::ostream &str, const StrMatcher &obj)
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &str, const StrMatcher &obj)
 
bool operator== (const StrMatcher &lhs, const StrMatcher &rhs)
 
bool operator!= (const StrMatcher &lhs, const StrMatcher &rhs)
 
bool operator< (const StrMatcher &lhs, const StrMatcher &rhs)
 

Detailed Description

String matching (STRING|SUBSTRING|GLOB|REGEX).

Used by e.g. PoolQuery and LookupAttr for queries, but it can also be used for matching arbitrary strings.

StrMatcher matches( "foo", Match::SUBSTRING );
for_( it, stringlist.begin(), stringlist().end() )
{
if ( matches( *it ) )
cout << *it << " has substring 'foo'" << endl;
}

Those flags are always set: REG_EXTENDED | REG_NOSUB | REG_NEWLINE

Definition at line 297 of file StrMatcher.h.

Member Typedef Documentation

◆ Exception

Definition at line 302 of file StrMatcher.h.

Constructor & Destructor Documentation

◆ StrMatcher() [1/9]

zypp::StrMatcher::StrMatcher ( )

Default ctor matches nothing.

Definition at line 260 of file StrMatcher.cc.

◆ StrMatcher() [2/9]

zypp::StrMatcher::StrMatcher ( const std::string &  search_r)

Ctor from string matches in Match::STRING mode per default.

Definition at line 264 of file StrMatcher.cc.

◆ StrMatcher() [3/9]

zypp::StrMatcher::StrMatcher ( std::string &&  search_r)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 267 of file StrMatcher.cc.

◆ StrMatcher() [4/9]

zypp::StrMatcher::StrMatcher ( const std::string &  search_r,
const Match flags_r 
)

Ctor taking string and Match flags.

Definition at line 271 of file StrMatcher.cc.

◆ StrMatcher() [5/9]

zypp::StrMatcher::StrMatcher ( std::string &&  search_r,
const Match flags_r 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 274 of file StrMatcher.cc.

◆ StrMatcher() [6/9]

zypp::StrMatcher::StrMatcher ( const std::string &  search_r,
const Match::Mode flags_r 
)

Ctor taking string and Match::Mode.

Needed because we want them to be treated as Match, and not as int as the compiler woud do.

Definition at line 278 of file StrMatcher.cc.

◆ StrMatcher() [7/9]

zypp::StrMatcher::StrMatcher ( std::string &&  search_r,
const Match::Mode flags_r 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 281 of file StrMatcher.cc.

◆ StrMatcher() [8/9]

zypp::StrMatcher::StrMatcher ( const std::string &  search_r,
int  flags_r 
)

Low level interface wraps flags into Match.

Definition at line 285 of file StrMatcher.cc.

◆ StrMatcher() [9/9]

zypp::StrMatcher::StrMatcher ( std::string &&  search_r,
int  flags_r 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 288 of file StrMatcher.cc.

Member Function Documentation

◆ operator bool()

zypp::StrMatcher::operator bool ( ) const
inlineexplicit

Evaluate in a boolean context ( ! searchstring().empty() ).

Definition at line 336 of file StrMatcher.h.

◆ operator()() [1/2]

template<class Tp >
bool zypp::StrMatcher::operator() ( const Tp &  string_r) const
inline

Return whether string matches.

You can use it with any class that impements c_str. (std::string, Pathname, IdString, ...). NULL never matches.

Definition at line 346 of file StrMatcher.h.

◆ operator()() [2/2]

bool zypp::StrMatcher::operator() ( const char *  string_r) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 349 of file StrMatcher.h.

◆ searchstring()

const std::string & zypp::StrMatcher::searchstring ( ) const

The current searchstring.

Definition at line 301 of file StrMatcher.cc.

◆ setSearchstring() [1/4]

void zypp::StrMatcher::setSearchstring ( const std::string &  string_r)

Set a new searchstring.

Definition at line 304 of file StrMatcher.cc.

◆ setSearchstring() [2/4]

void zypp::StrMatcher::setSearchstring ( std::string &&  string_r)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 306 of file StrMatcher.cc.

◆ setSearchstring() [3/4]

void zypp::StrMatcher::setSearchstring ( const std::string &  string_r,
const Match flags_r 
)

Set a new searchstring and flags.

Definition at line 309 of file StrMatcher.cc.

◆ setSearchstring() [4/4]

void zypp::StrMatcher::setSearchstring ( std::string &&  string_r,
const Match flags_r 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 314 of file StrMatcher.cc.

◆ flags()

const Match & zypp::StrMatcher::flags ( ) const

The current search flags.

Definition at line 320 of file StrMatcher.cc.

◆ setFlags()

void zypp::StrMatcher::setFlags ( const Match flags_r)

Set new search flags.

Definition at line 323 of file StrMatcher.cc.

◆ compile()

void zypp::StrMatcher::compile ( ) const

Compile the pattern e.g.

in case of REGEX.

Exceptions
MatchUnknownModeExceptionIf the Match flag more than one mode bit set.
MatchInvalidRegexExceptionIf Match::REGEX is set and searchstring is not a valid regular expression.

Definition at line 292 of file StrMatcher.cc.

◆ isCompiled()

bool zypp::StrMatcher::isCompiled ( ) const

Whether the StrMatcher is already compiled.

Definition at line 295 of file StrMatcher.cc.

◆ doMatch()

bool zypp::StrMatcher::doMatch ( const char *  string_r) const

Return whether string matches.

Compiles the StrMatcher if this was not yet done.

Exceptions
MatchExceptionAny of the exceptions thrown by StrMatcher::compile.

Definition at line 298 of file StrMatcher.cc.

Friends And Related Function Documentation

◆ operator<< [1/2]

std::ostream& operator<< ( std::ostream &  str,
const StrMatcher obj 
)
friend

Definition at line 326 of file StrMatcher.cc.

◆ operator<<() [2/2]

std::ostream & operator<< ( std::ostream &  str,
const StrMatcher obj 
)
related

Stream output

Definition at line 326 of file StrMatcher.cc.

◆ operator==()

bool operator== ( const StrMatcher lhs,
const StrMatcher rhs 
)
related

Definition at line 329 of file StrMatcher.cc.

◆ operator!=()

bool operator!= ( const StrMatcher lhs,
const StrMatcher rhs 
)
related

Definition at line 402 of file StrMatcher.h.

◆ operator<()

bool operator< ( const StrMatcher lhs,
const StrMatcher rhs 
)
related

Arbitrary order for std::container.

Definition at line 335 of file StrMatcher.cc.

Member Data Documentation

◆ _pimpl

RWCOW_pointer<Impl> zypp::StrMatcher::_pimpl
private

Pointer to implementation.

Definition at line 392 of file StrMatcher.h.


The documentation for this class was generated from the following files: