fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::RegExp Class Reference

POSIX regex wrapper class. More...

#include <f8utils.hpp>

Public Member Functions

 RegExp (const char *pattern, const int flags=0)
 
virtual ~RegExp ()
 Dtor. Destroys internal compiled expression. More...
 
int SearchString (RegMatch &match, const std::string &source, const int subExpr, const int offset=0) const
 
const std::string & GetPattern () const
 
const std::string & ErrString () const
 
bool operator! () const
 
 operator void * ()
 

Static Public Member Functions

static std::string & SubExpr (RegMatch &match, const std::string &source, std::string &target, const int offset=0, const int num=0)
 
static std::string & Erase (RegMatch &match, std::string &source, const int num=0)
 
static std::string & Replace (RegMatch &match, std::string &source, const std::string &with, const int num=0)
 
static std::string & Replace (RegMatch &match, std::string &source, const char with, const int num=0)
 

Private Types

enum  { MaxErrLen_ = 256 }
 Maximum length of an error message. More...
 

Private Attributes

const std::string pattern_
 
regex_t reg_
 
std::string errString
 
int errCode_
 

Detailed Description

POSIX regex wrapper class.

Definition at line 370 of file f8utils.hpp.

Member Enumeration Documentation

anonymous enum
private

Maximum length of an error message.

Enumerator
MaxErrLen_ 

Definition at line 375 of file f8utils.hpp.

Constructor & Destructor Documentation

FIX8::RegExp::RegExp ( const char *  pattern,
const int  flags = 0 
)
inline

Ctor.

Parameters
patternregular expression to compile. errCode and errString set on error.
flagsPOSIX regcomp flags

Definition at line 388 of file f8utils.hpp.

References MaxErrLen_.

390  : pattern_(pattern)
391  {
392  if ((errCode_ = regcomp(&reg_, pattern_.c_str(), REG_EXTENDED|flags)) != 0)
393  {
394  char rbuf[MaxErrLen_];
395  regerror(errCode_, &reg_, rbuf, MaxErrLen_);
396  errString = rbuf;
397  }
398  }
regex_t reg_
Definition: f8utils.hpp:377
const std::string pattern_
Definition: f8utils.hpp:372
std::string errString
Definition: f8utils.hpp:381
virtual FIX8::RegExp::~RegExp ( )
inlinevirtual

Dtor. Destroys internal compiled expression.

Definition at line 415 of file f8utils.hpp.

416  {
417 #if FIX8_REGEX_SYSTEM == FIX8_REGEX_REGEX_H
418  if (errCode_ == 0)
419  regfree(&reg_);
420 #elif FIX8_REGEX_SYSTEM == FIX8_REGEX_POCO
421  delete _regexp;
422 #endif
423  }
regex_t reg_
Definition: f8utils.hpp:377

Member Function Documentation

static std::string& FIX8::RegExp::Erase ( RegMatch match,
std::string &  source,
const int  num = 0 
)
inlinestatic

Erase a sub-expression from a string.

Parameters
matchreference to a RegMatch object
sourcesource string
numdesired sub-expression
Returns
the source string

Definition at line 471 of file f8utils.hpp.

References FIX8::RegMatch::SubCnt(), FIX8::RegMatch::subCnt_, FIX8::RegMatch::subexprs_, FIX8::RegMatch::SubPos(), and FIX8::RegMatch::SubSize().

Referenced by main().

472  {
473 #if FIX8_REGEX_SYSTEM == FIX8_REGEX_REGEX_H
474  if (num < match.subCnt_)
475  source.erase(match.subexprs_[num].rm_so, match.subexprs_[num].rm_eo - match.subexprs_[num].rm_so);
476 #elif FIX8_REGEX_SYSTEM == FIX8_REGEX_POCO
477  if (num < static_cast<int>(match.SubCnt()))
478  source.erase(match.SubPos(num), match.SubSize(num));
479 #endif
480  return source;
481  }
const std::string& FIX8::RegExp::ErrString ( ) const
inline

Get the error string (set when Ctor fails to compile).

Returns
the error string

Definition at line 525 of file f8utils.hpp.

References errString.

525 { return errString; }
std::string errString
Definition: f8utils.hpp:381
const std::string& FIX8::RegExp::GetPattern ( ) const
inline

Get the regular expression pattern.

Returns
the pattern string

Definition at line 521 of file f8utils.hpp.

References pattern_.

521 { return pattern_; }
const std::string pattern_
Definition: f8utils.hpp:372
FIX8::RegExp::operator void * ( )
inline

Check if a pattern compiled ok.

Returns
true onsuccess

Definition at line 533 of file f8utils.hpp.

533 { return errCode_ ? 0 : this; }
bool FIX8::RegExp::operator! ( ) const
inline

Check if a pattern did not compile ok.

Returns
true on failure

Definition at line 529 of file f8utils.hpp.

References errCode_.

529 { return errCode_; }
static std::string& FIX8::RegExp::Replace ( RegMatch match,
std::string &  source,
const std::string &  with,
const int  num = 0 
)
inlinestatic

Replace a sub-expression with a string.

Parameters
matchreference to a RegMatch object
sourcesource string
withreplacement string
numdesired sub-expression
Returns
the source string

Definition at line 489 of file f8utils.hpp.

References FIX8::RegMatch::SubCnt(), FIX8::RegMatch::subCnt_, FIX8::RegMatch::subexprs_, FIX8::RegMatch::SubPos(), and FIX8::RegMatch::SubSize().

Referenced by XmlElement::InplaceXlate().

490  {
491 #if FIX8_REGEX_SYSTEM == FIX8_REGEX_REGEX_H
492  if (num < match.subCnt_)
493  source.replace(match.subexprs_[num].rm_so, match.subexprs_[num].rm_eo - match.subexprs_[num].rm_so, with);
494 #elif FIX8_REGEX_SYSTEM == FIX8_REGEX_POCO
495  if (num < static_cast<int>(match.SubCnt()))
496  source.replace(match.SubPos(num), match.SubSize(num), with);
497 #endif
498  return source;
499  }
static std::string& FIX8::RegExp::Replace ( RegMatch match,
std::string &  source,
const char  with,
const int  num = 0 
)
inlinestatic

Replace a sub-expression with a character.

Parameters
matchreference to a RegMatch object
sourcesource string
withreplacement character
numdesired sub-expression
Returns
the source string

Definition at line 507 of file f8utils.hpp.

References FIX8::RegMatch::SubCnt(), FIX8::RegMatch::subCnt_, FIX8::RegMatch::subexprs_, FIX8::RegMatch::SubPos(), and FIX8::RegMatch::SubSize().

508  {
509 #if FIX8_REGEX_SYSTEM == FIX8_REGEX_REGEX_H
510  if (num < match.subCnt_)
511  source.replace(match.subexprs_[num].rm_so, match.subexprs_[num].rm_eo - match.subexprs_[num].rm_so, 1, with);
512 #elif FIX8_REGEX_SYSTEM == FIX8_REGEX_POCO
513  if (num < static_cast<int>(match.SubCnt()))
514  source.replace(match.SubPos(num), match.SubSize(num), 1, with);
515 #endif
516  return source;
517  }
int FIX8::RegExp::SearchString ( RegMatch match,
const std::string &  source,
const int  subExpr,
const int  offset = 0 
) const
inline

Search a string.

Parameters
matchreference to a RegMatch object
sourcestring to search
subExprnumber of sub-expression
offsetto start searching
Returns
number of sub-expressions found (0=none)

Definition at line 431 of file f8utils.hpp.

References FIX8::RegMatch::subCnt_, FIX8::RegMatch::subexprs_, and FIX8::RegMatch::SubLimit_.

Referenced by XmlElement::InplaceXlate(), and main().

432  {
433 #if FIX8_REGEX_SYSTEM == FIX8_REGEX_REGEX_H
434  match.subCnt_ = 0;
435  if (regexec(&reg_, source.c_str() + offset, subExpr <= RegMatch::SubLimit_ ? subExpr : RegMatch::SubLimit_, match.subexprs_, 0) == 0)
436  while (match.subCnt_ < subExpr && match.subexprs_[match.subCnt_].rm_so != -1)
437  ++match.subCnt_;
438  return match.subCnt_;
439 #elif FIX8_REGEX_SYSTEM == FIX8_REGEX_POCO
440  match._matchVec.clear();
441  return _regexp ? _regexp->match(source, offset, match._matchVec) : 0;
442 #endif
443  }
regex_t reg_
Definition: f8utils.hpp:377
static std::string& FIX8::RegExp::SubExpr ( RegMatch match,
const std::string &  source,
std::string &  target,
const int  offset = 0,
const int  num = 0 
)
inlinestatic

Extract a sub-expression.

Parameters
matchreference to a RegMatch object
sourcesource string
targetlocation to place sub-experssion
offsetto start searching
numdesired sub-expression
Returns
the target string

Definition at line 452 of file f8utils.hpp.

References FIX8::RegMatch::SubCnt(), FIX8::RegMatch::subCnt_, FIX8::RegMatch::subexprs_, FIX8::RegMatch::SubPos(), and FIX8::RegMatch::SubSize().

Referenced by XmlElement::InplaceXlate(), and main().

453  {
454 #if FIX8_REGEX_SYSTEM == FIX8_REGEX_REGEX_H
455  if (num < match.subCnt_)
456  target = source.substr(offset + match.subexprs_[num].rm_so, match.subexprs_[num].rm_eo - match.subexprs_[num].rm_so);
457 #elif FIX8_REGEX_SYSTEM == FIX8_REGEX_POCO
458  if (num < static_cast<int>(match.SubCnt()))
459  target = source.substr(offset + match.SubPos(num), match.SubSize(num));
460 #endif
461  else
462  target.empty();
463  return target;
464  }

Member Data Documentation

int FIX8::RegExp::errCode_
private

Definition at line 382 of file f8utils.hpp.

Referenced by operator!().

std::string FIX8::RegExp::errString
private

Definition at line 381 of file f8utils.hpp.

Referenced by ErrString().

const std::string FIX8::RegExp::pattern_
private

Definition at line 372 of file f8utils.hpp.

Referenced by GetPattern().

regex_t FIX8::RegExp::reg_
private

Definition at line 377 of file f8utils.hpp.


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