libcsdbg  1.28
C++ exception (and generic) stack trace debug library
bool csdbg::string::match ( const string exp,
bool  icase = false 
) const
virtual

Match against a POSIX extended regular expression.

Parameters
[in]expthe regular expression
[in]icasetrue to ignore case sensitivity
Returns
true if there is a match, false otherwise
Exceptions
csdbg::exception

Definition at line 490 of file string.cpp.

References cstr(), likely, m_data, and unlikely.

Referenced by csdbg::parser::highlight(), csdbg::dictionary::lookup(), csdbg::tracer::on_dso_load(), and split().

491 {
492  i32 flags = REG_EXTENDED | REG_NOSUB;
493  if ( unlikely(icase) )
494  flags |= REG_ICASE;
495 
496  /* Compile the regular expression and perform the matching */
497  regex_t regexp;
498  i32 retval = regcomp(&regexp, exp.cstr(), flags);
499  if ( likely(retval == 0) ) {
500  retval = regexec(&regexp, m_data, 0, NULL, 0);
501  regfree(&regexp);
502  return !retval;
503  }
504 
505  /* If the expression compilation failed */
506  i32 len = regerror(retval, &regexp, NULL, 0);
507  i8 errbuf[len];
508  regerror(retval, &regexp, errbuf, len);
509  regfree(&regexp);
510 
511  throw exception(
512  "failed to compile regexp '%s' (regex errno %d - %s)",
513  exp.cstr(),
514  retval,
515  errbuf
516  );
517 }
char i8
8-bit signed integer
Definition: config.hpp:72
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
i8 * m_data
String data.
Definition: string.hpp:42
int i32
32-bit signed integer
Definition: config.hpp:82
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349

+ Here is the call graph for this function:

+ Here is the caller graph for this function: