Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes

bdlpcre::RegEx Class Reference

#include <bdlpcre_regex.h>

List of all members.

Public Types

enum  {
  k_FLAG_CASELESS = 1 << 0, k_FLAG_DOTMATCHESALL = 1 << 1, k_FLAG_MULTILINE = 1 << 2, k_FLAG_UTF8 = 1 << 3,
  k_FLAG_JIT = 1 << 4
}
enum  {
  k_REPLACE_LITERAL = 1 << 0, k_REPLACE_GLOBAL = 1 << 1, k_REPLACE_EXTENDED = 1 << 2, k_REPLACE_UNKNOWN_UNSET = 1 << 3,
  k_REPLACE_UNSET_EMPTY = 1 << 4
}

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (RegEx, bslma::UsesBslmaAllocator)
 RegEx (bslma::Allocator *basicAllocator=0)
 ~RegEx ()
void clear ()
int prepare (bsl::nullptr_t errorMessage, size_t *errorOffset, const char *pattern, int flags=0, size_t jitStackSize=0)
template<class STRING >
bsl::enable_if< bsl::is_same
< STRING, bsl::string >::value||bsl::is_same
< STRING, std::string >::value,
int >::type 
prepare (STRING *errorMessage, size_t *errorOffset, const char *pattern, int flags=0, size_t jitStackSize=0)
int setDepthLimit (int depthLimit)
int depthLimit () const
int flags () const
bool isPrepared () const
size_t jitStackSize () const
int match (const bsl::string_view &subject, size_t subjectOffset=0) const
int match (const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int match (bsl::pair< size_t, size_t > *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int match (bsl::string_view *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int match (bsl::string_view *result, const bsl::string_view &subject, size_t subjectOffset=0) const
int match (bsl::vector< bsl::pair< size_t, size_t > > *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int match (bsl::vector< bslstl::StringRef > *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int match (bsl::vector< bsl::string_view > *result, const bsl::string_view &subject, size_t subjectOffset=0) const
int match (std::vector< bsl::string_view > *result, const bsl::string_view &subject, size_t subjectOffset=0) const
int matchRaw (const bsl::string_view &subject, size_t subjectOffset=0) const
int matchRaw (const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int matchRaw (bsl::pair< size_t, size_t > *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int matchRaw (bsl::string_view *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int matchRaw (bsl::string_view *result, const bsl::string_view &subject, size_t subjectOffset=0) const
int matchRaw (bsl::vector< bsl::pair< size_t, size_t > > *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int matchRaw (bsl::vector< bslstl::StringRef > *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int matchRaw (bsl::vector< bsl::string_view > *result, const bsl::string_view &subject, size_t subjectOffset=0) const
int matchRaw (std::vector< bsl::string_view > *result, const bsl::string_view &subject, size_t subjectOffset=0) const
int numSubpatterns () const
const bsl::stringpattern () const
int replace (bsl::string *result, int *errorOffset, const bsl::string_view &subject, const bsl::string_view &replacement, size_t options=0) const
int replace (std::string *result, int *errorOffset, const bsl::string_view &subject, const bsl::string_view &replacement, size_t options=0) const
int replaceRaw (bsl::string *result, int *errorOffset, const bsl::string_view &subject, const bsl::string_view &replacement, size_t options=0) const
int replaceRaw (std::string *result, int *errorOffset, const bsl::string_view &subject, const bsl::string_view &replacement, size_t options=0) const
int subpatternIndex (const char *name) const

Static Public Member Functions

static int defaultDepthLimit ()
static bool isJitAvailable ()
static int setDefaultDepthLimit (int depthLimit)

Static Public Attributes

static const size_t k_INVALID_OFFSET

Detailed Description

This class provides a mechanism for compiling and matching regular expressions. A regular expression approximately compatible with Perl 5.10 is compiled with the prepare method. Subsequently, strings are matched against the compiled (prepared) pattern using the overloaded match and matchRaw methods. Note that the underlying implementation uses the open-source Perl Compatible Regular Expressions (PCRE2) library that was developed at the University of Cambridge (http://www.pcre.org/).

See Component bdlpcre_regex


Member Enumeration Documentation

anonymous enum

This enumeration defines the flags that may be supplied to prepare to affect specific pattern matching behavior.

Enumerator:
k_FLAG_CASELESS 

case-insensitive matching

k_FLAG_DOTMATCHESALL 

dot metacharacter matches all chars (including newlines)

k_FLAG_MULTILINE 

multi-line matching

k_FLAG_UTF8 

UTF-8 support.

k_FLAG_JIT 

just-in-time compiling optimization requested

anonymous enum

This enumeration defines the flags that may be supplied to replace to affect specific replacement behavior.

Enumerator:
k_REPLACE_LITERAL 

the replacement string is literal

k_REPLACE_GLOBAL 

replace all occurrences in the subject

k_REPLACE_EXTENDED 

do extended replacement processing

k_REPLACE_UNKNOWN_UNSET 

treat unknown group as unset

k_REPLACE_UNSET_EMPTY 

simple unset insert = empty string


Constructor & Destructor Documentation

bdlpcre::RegEx::RegEx ( bslma::Allocator basicAllocator = 0  ) 

IMPLICIT: Create a regular-expression object in the "unprepared" state. Optionally specify a basicAllocator used to supply memory. The alignment strategy of the allocator must be "maximum" or "natural". If basicAllocator is 0, the currently installed default allocator is used.

bdlpcre::RegEx::~RegEx (  ) 

Destroy this regular-expression object.


Member Function Documentation

bdlpcre::RegEx::BSLMF_NESTED_TRAIT_DECLARATION ( RegEx  ,
bslma::UsesBslmaAllocator   
)
static int bdlpcre::RegEx::defaultDepthLimit (  )  [static]

Return the process-wide default evaluation recursion depth limit.

static bool bdlpcre::RegEx::isJitAvailable (  )  [static]

Return true if just-in-time compiling optimization is supported by current hardware platform and false otherwise. Note that JIT support is limited to the following hardware platforms:

          ARM 32-bit (v5, v7, and Thumb2)
          ARM 64-bit
          Intel x86 32-bit and 64-bit
          MIPS 32-bit and 64-bit
          Power PC 32-bit and 64-bit
          SPARC 32-bit
static int bdlpcre::RegEx::setDefaultDepthLimit ( int  depthLimit  )  [static]

Set the process-wide default evaluation recursion depth limit to the specified depthLimit. Return the previous depth limit.

void bdlpcre::RegEx::clear (  ) 

Free resources used by this regular-expression object and put this object into the "unprepared" state. This method has no effect if this object is already in the "unprepared" state.

int bdlpcre::RegEx::prepare ( bsl::nullptr_t  errorMessage,
size_t *  errorOffset,
const char *  pattern,
int  flags = 0,
size_t  jitStackSize = 0 
)
template<class STRING >
bsl::enable_if< bsl::is_same<STRING, bsl::string>::value || bsl::is_same<STRING, std::string>::value , int>::type bdlpcre::RegEx::prepare ( STRING *  errorMessage,
size_t *  errorOffset,
const char *  pattern,
int  flags = 0,
size_t  jitStackSize = 0 
)

Prepare this regular-expression object with the specified pattern and the optionally specified flags. flags, if supplied, should contain a bit-wise or of the k_FLAG_* constants defined by this class, which indicate additional configuration parameters for the regular expression. Optionally specify jitStackSize. If flags has the k_FLAG_JIT flag set, jitStackSize indicates the size of the allocated JIT stack to be used for this pattern. If flags has the k_FLAG_JIT bit set and jitStackSize is 0 (or not supplied), no memory will be allocated for the JIT stack and the program stack will be used as the JIT stack. If flags does not have k_FLAG_JIT set, or isJitAvailable() is false, the jitStackSize parameter, if supplied, is ignored. On success, put this object into the "prepared" state and return 0, with no effect on the specified errorMessage and errorOffset. Otherwise, (1) put this object into the "unprepared" state, (2) load errorMessage (if non-null) with a string describing the error detected, (3) load errorOffset (if non-null) with the offset in pattern at which the error was detected, and (4) return a non-zero value. The behavior is undefined unless flags is the bit-wise inclusive-or of 0 or more of the following values:

Note that the flag k_FLAG_JIT is ignored if isJitAvailable() is false.

int bdlpcre::RegEx::setDepthLimit ( int  depthLimit  ) 

Set the evaluation recursion depth limit for this regular-expression object to the specified depthLimit. Return the previous depth limit.

int bdlpcre::RegEx::depthLimit (  )  const

Return the evaluation recursion depth limit for this regular-expression object.

int bdlpcre::RegEx::flags (  )  const

Return the flags that were supplied to the most recent successful call to the prepare method of this regular-expression object. The behavior is undefined unless isPrepared() == true. Note that the returned value will be the bit-wise inclusive-or of 0 or more of the following values:

Also note that k_FLAG_JIT is ignored, but still returned by this method, if isJitAvailable() is false.

bool bdlpcre::RegEx::isPrepared (  )  const

Return true if this regular-expression object is in the "prepared" state, and false otherwise.

size_t bdlpcre::RegEx::jitStackSize (  )  const

Return the size of the dynamically allocated JIT stack if it has been specified explicitly with the prepare method. Return 0 if a zero jitStackSize value was passed to the prepare method (or not supplied at all) or if isPrepared() is false.

int bdlpcre::RegEx::match ( const bsl::string_view &  subject,
size_t  subjectOffset = 0 
) const

Match the specified subject against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. UTF-8 validity checking is performed on subject if pattern() was prepared with k_FLAG_UTF8. Return:

  • 0 on success
  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, for example, if pattern() was prepared with k_FLAG_UTF8, but subject is not valid UTF-8

The behavior is undefined unless true == isPrepared() and subjectOffset <= subject.length(). Note that JIT optimization is disabled if pattern() was prepared with k_FLAG_UTF8; use matchRaw if JIT is preferred and UTF-8 validation of subject is not required.

int bdlpcre::RegEx::match ( const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const

Match the specified subject having the specified subjectLength against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. subject may contain embedded null characters. UTF-8 validity checking is performed on subject if pattern() was prepared with k_FLAG_UTF8. Return:

  • 0 on success
  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, for example, if pattern() was prepared with k_FLAG_UTF8, but subject is not valid UTF-8

The behavior is undefined unless true == isPrepared(), subject || 0 == subjectLength, and subjectOffset <= subjectLength. Note that JIT optimization is disabled if pattern() was prepared with k_FLAG_UTF8; use matchRaw if JIT is preferred and UTF-8 validation of subject is not required.

int bdlpcre::RegEx::match ( bsl::pair< size_t, size_t > *  result,
const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const
int bdlpcre::RegEx::match ( bsl::string_view *  result,
const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const

Match the specified subject having the specified subjectLength against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. subject may contain embedded null characters. UTF-8 validity checking is performed on subject if pattern() was prepared with k_FLAG_UTF8. Return:

  • 0 on success and load the specified result with, respectively, a (offset, length) pair or a bsl::string_view indicating the leftmost match of pattern()
  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, for example, if pattern() was prepared with k_FLAG_UTF8, but subject is not valid UTF-8

result is unchanged if a non-zero value is returned. The behavior is undefined unless true == isPrepared(), subject || 0 == subjectLength, and subjectOffset <= subjectLength. Note that JIT optimization is disabled if pattern() was prepared with k_FLAG_UTF8; use matchRaw if JIT is preferred and UTF-8 validation of subject is not required.

int bdlpcre::RegEx::match ( bsl::string_view *  result,
const bsl::string_view &  subject,
size_t  subjectOffset = 0 
) const

Match the specified subject against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. UTF-8 validity checking is performed on subject if pattern() was prepared with k_FLAG_UTF8. Return:

  • 0 on success and load the specified result with a bsl::string_view indicating the leftmost match of pattern()
  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, for example, if pattern() was prepared with k_FLAG_UTF8, but subject is not valid UTF-8

result is unchanged if a non-zero value is returned. The behavior is undefined unless true == isPrepared() and subjectOffset <= subject.length(). Note that JIT optimization is disabled if pattern() was prepared with k_FLAG_UTF8; use matchRaw if JIT is preferred and UTF-8 validation of subject is not required.

int bdlpcre::RegEx::match ( bsl::vector< bsl::pair< size_t, size_t > > *  result,
const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const
int bdlpcre::RegEx::match ( bsl::vector< bslstl::StringRef > *  result,
const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const

Match the specified subject having the specified subjectLength against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. subject may contain embedded null characters. UTF-8 validity checking is performed on subject if pattern() was prepared with k_FLAG_UTF8. On success:

  1. Load the first element of the specified result with, respectively, a (offset, length) pair or a bslstl::StringRef indicating the leftmost match of pattern().
  2. Load elements of result in the range [1 .. numSubpatterns()] with, respectively, a (offset, length) pair or a bslstl::StringRef indicating the respective matches of sub-patterns (unmatched sub-patterns have their respective result elements loaded with either the (k_INVALID_OFFSET, 0) pair or an empty bslstl::StringRef); sub-patterns matching multiple times have their respective result elements loaded with the pairs or bslstl::StringRef indicating the rightmost match, and return 0.

Otherwise, return:

  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, for example, if pattern() was prepared with k_FLAG_UTF8, but subject is not valid UTF-8

result is unchanged if a non-zero value is returned. The behavior is undefined unless true == isPrepared(), subject || 0 == subjectLength, and subjectOffset <= subjectLength. Note that JIT optimization is disabled if pattern() was prepared with k_FLAG_UTF8; use matchRaw if JIT is preferred and UTF-8 validation of subject is not required. Also note that after a successful call, result will contain exactly numSubpatterns() + 1 elements.

int bdlpcre::RegEx::match ( bsl::vector< bsl::string_view > *  result,
const bsl::string_view &  subject,
size_t  subjectOffset = 0 
) const
int bdlpcre::RegEx::match ( std::vector< bsl::string_view > *  result,
const bsl::string_view &  subject,
size_t  subjectOffset = 0 
) const

Match the specified subject against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. UTF-8 validity checking is performed on subject if pattern() was prepared with k_FLAG_UTF8. On success:

  1. Load the first element of the specified result with a bsl::string_view indicating the leftmost match of pattern().
  2. Load elements of result in the range [1 .. numSubpatterns()] with a bsl::string_view indicating the respective matches of sub-patterns (unmatched sub-patterns have their respective result elements loaded with an empty bsl::string_view); sub-patterns matching multiple times have their respective result elements loaded with a bsl::string_view indicating the rightmost match, and return 0.

Otherwise, return:

  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, for example, if pattern() was prepared with k_FLAG_UTF8, but subject is not valid UTF-8

result is unchanged if a non-zero value is returned. The behavior is undefined unless true == isPrepared() and subjectOffset <= subject.length(). Note that JIT optimization is disabled if pattern() was prepared with k_FLAG_UTF8; use matchRaw if JIT is preferred and UTF-8 validation of subject is not required. Also note that after a successful call, result will contain exactly numSubpatterns() + 1 elements.

int bdlpcre::RegEx::matchRaw ( const bsl::string_view &  subject,
size_t  subjectOffset = 0 
) const

Match the specified subject against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. Return:

  • 0 on success
  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, otherwise

The behavior is undefined unless true == isPrepared(), subjectOffset <= subject.length(), and subject is valid UTF-8 if pattern() was prepared with k_FLAG_UTF8.

int bdlpcre::RegEx::matchRaw ( const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const

Match the specified subject having the specified subjectLength against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. subject may contain embedded null characters. Return:

  • 0 on success
  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, otherwise

The behavior is undefined unless true == isPrepared(), subject || 0 == subjectLength, subjectOffset <= subjectLength, and subject is valid UTF-8 if pattern() was prepared with k_FLAG_UTF8.

int bdlpcre::RegEx::matchRaw ( bsl::pair< size_t, size_t > *  result,
const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const
int bdlpcre::RegEx::matchRaw ( bsl::string_view *  result,
const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const

Match the specified subject having the specified subjectLength against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. subject may contain embedded null characters. Return:

  • 0 on success and load the specified result with, respectively, a (offset, length) pair or a bsl::string_view indicating the leftmost match of pattern()
  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, otherwise

result is unchanged if a non-zero value is returned. The behavior is undefined unless true == isPrepared(), subject || 0 == subjectLength, subjectOffset <= subjectLength, and subject is valid UTF-8 if pattern() was prepared with k_FLAG_UTF8.

int bdlpcre::RegEx::matchRaw ( bsl::string_view *  result,
const bsl::string_view &  subject,
size_t  subjectOffset = 0 
) const

Match the specified subject against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. Return:

  • 0 on success and load the specified result with a bsl::string_view indicating the leftmost match of pattern()
  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value, otherwise

result is unchanged if a non-zero value is returned. The behavior is undefined unless true == isPrepared(), subjectOffset <= subject.length(), and subject is valid UTF-8 if pattern() was prepared with k_FLAG_UTF8.

int bdlpcre::RegEx::matchRaw ( bsl::vector< bsl::pair< size_t, size_t > > *  result,
const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const
int bdlpcre::RegEx::matchRaw ( bsl::vector< bslstl::StringRef > *  result,
const char *  subject,
size_t  subjectLength,
size_t  subjectOffset = 0 
) const

Match the specified subject having the specified subjectLength against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. subject may contain embedded null characters. On success:

  1. Load the first element of the specified result with, respectively, a (offset, length) pair or a bslstl::StringRef indicating the leftmost match of pattern().
  2. Load elements of result in the range [1 .. numSubpatterns()] with, respectively, a (offset, length) pair or a bslstl::StringRef indicating the respective matches of sub-patterns (unmatched sub-patterns have their respective result elements loaded with either the (k_INVALID_OFFSET, 0) pair or an empty bslstl::StringRef); sub-patterns matching multiple times have their respective result elements loaded with the pairs or bslstl::StringRef indicating the rightmost match, and return 0.

Otherwise, return:

  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value

result is unchanged if a non-zero value is returned. The behavior is undefined unless true == isPrepared(), subject || 0 == subjectLength, subjectOffset <= subjectLength, and subject is valid UTF-8 if pattern() was prepared with k_FLAG_UTF8. Note that after a successful call, result will contain exactly numSubpatterns() + 1 elements.

int bdlpcre::RegEx::matchRaw ( bsl::vector< bsl::string_view > *  result,
const bsl::string_view &  subject,
size_t  subjectOffset = 0 
) const
int bdlpcre::RegEx::matchRaw ( std::vector< bsl::string_view > *  result,
const bsl::string_view &  subject,
size_t  subjectOffset = 0 
) const

Match the specified subject against pattern(). Begin matching at the optionally specified subjectOffset in subject. If subjectOffset is not specified, matching begins at the start of subject. On success:

  1. Load the first element of the specified result with a bsl::string_view indicating the leftmost match of pattern().
  2. Load elements of result in the range [1 .. numSubpatterns()] with a bsl::string_view indicating the respective matches of sub-patterns (unmatched sub-patterns have their respective result elements loaded with an empty bsl::string_view); sub-patterns matching multiple times have their respective result elements loaded with a bsl::string_view indicating the rightmost match, and return 0.

Otherwise, return:

  • 1 if depthLimit() was exceeded
  • 2 if memory available for the JIT stack is not large enough (applicable only if pattern() was prepared with k_FLAG_JIT)
  • another non-zero value

result is unchanged if a non-zero value is returned. The behavior is undefined unless true == isPrepared(), subjectOffset <= subject.length(), and subject is valid UTF-8 if pattern() was prepared with k_FLAG_UTF8. Also note that after a successful call, result will contain exactly numSubpatterns() + 1 elements.

int bdlpcre::RegEx::numSubpatterns (  )  const

Return the number of sub-patterns in the pattern held by this regular-expression object (pattern()). The behavior is undefined unless isPrepared() == true.

const bsl::string& bdlpcre::RegEx::pattern (  )  const

Return a reference to the non-modifiable pattern held by this regular-expression object. The behavior is undefined unless isPrepared() == true.

int bdlpcre::RegEx::replace ( bsl::string result,
int *  errorOffset,
const bsl::string_view &  subject,
const bsl::string_view &  replacement,
size_t  options = 0 
) const
int bdlpcre::RegEx::replace ( std::string *  result,
int *  errorOffset,
const bsl::string_view &  subject,
const bsl::string_view &  replacement,
size_t  options = 0 
) const

Replace parts of the specified subject that are matched with the specified replacement. Optionally specify a bit mask of options flags that configure the behavior of the replacement. options should contain a bit-wise OR of the k_REPLACE_* constants defined by this class, which indicate additional configuration parameters for the replacement. If options has k_REPLACE_GLOBAL flag then this function iterates over subject, replacing every matching substring. If k_REPLACE_GLOBAL flag is not set, only the first matching substring is replaced. UTF-8 validity checking is performed on subject and replacement if pattern() was prepared with k_FLAG_UTF8. Return the number of substitutions that were carried out on success, and load the specified result with the result of the replacement. Otherwise, if an error occurs, return a negative value. If that error is a syntax error in replacement, load the specified errorOffset (if non-null) with the offset in replacement where the error was detected; for other errors, such as invalid subject or replacement UTF-8 string, load errorOffset with a negative value. The behavior is undefined unless true == isPrepared(). Note that if the size of result is too small to fit the resultant string then this method computes the size of result and adjusts it to the size that is needed. To avoid automatic calculation and adjustment which may introduce a performance penalty, it is recommended that the size of result has enough room to fit the resulting string including a zero-terminating character.

int bdlpcre::RegEx::replaceRaw ( bsl::string result,
int *  errorOffset,
const bsl::string_view &  subject,
const bsl::string_view &  replacement,
size_t  options = 0 
) const
int bdlpcre::RegEx::replaceRaw ( std::string *  result,
int *  errorOffset,
const bsl::string_view &  subject,
const bsl::string_view &  replacement,
size_t  options = 0 
) const

Replace parts of the specified subject that are matched with the specified replacement. Optionally specify a bit mask of options flags that configure the behavior of the replacement. options should contain a bit-wise OR of the k_REPLACE_* constants defined by this class, which indicate additional configuration parameters for the replacement. If options has k_REPLACE_GLOBAL flag then this function iterates over subject, replacing every matching substring. If k_REPLACE_GLOBAL flag is not set, only the first matching substring is replaced. UTF-8 validity checking is performed on subject if pattern() was prepared with k_FLAG_UTF8. Return the number of substitutions that were carried out on success, and load the specified result with the result of the replacement. Otherwise, if an error occurs, return a negative value. If that error is a syntax error in replacement, load the specified errorOffset (if non-null) with the offset in replacement where the error was detected; for other errors, such as invalid subject UTF-8 string, load errorOffset with a negative value. The behavior is undefined unless true == isPrepared(). Note that if the size of result is too small to fit the resultant string then this method computes the size of result and adjusts it to the size that is needed. To avoid automatic calculation and adjustment which may introduce a performance penalty, it is recommended that the size of result has enough room to fit the resulting string including a zero-terminating character.

int bdlpcre::RegEx::subpatternIndex ( const char *  name  )  const

Return the 1-based index of the sub-pattern having the specified name in the pattern held by this regular-expression object (pattern()); return -1 if pattern() does not contain a sub-pattern identified by name. The behavior is undefined unless isPrepared() == true. Note that the returned value is intended to be used as an index into the bsl::vector<bsl::pair<int, int> > returned by match.


Member Data Documentation

const size_t bdlpcre::RegEx::k_INVALID_OFFSET [static]

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