8#ifndef INCLUDED_BDLPCRE_REGEX
9#define INCLUDED_BDLPCRE_REGEX
715#include <bdlscm_version.h>
728#include <bsl_cstddef.h>
729#include <bsl_string.h>
730#include <bsl_string_view.h>
731#include <bsl_utility.h>
732#include <bsl_vector.h>
738#define PCRE2_CODE_UNIT_WIDTH 8
740#include <pcre2/pcre2.h>
743#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
750class RegEx_MatchContext;
770 bsls::AtomicOperations::AtomicTypes::Int s_depthLimit;
780 pcre2_general_context *d_pcre2Context_p;
782 pcre2_compile_context *d_compileContext_p;
784 pcre2_code *d_patternCode_p;
788 size_t d_jitStackSize;
824 int prepareImp(
char *errorBuffer,
825 size_t errorBufferLength,
848 template <
class RESULT_EXTRACTOR>
849 int matchImp(
const RESULT_EXTRACTOR& extractor,
851 size_t subjectLength,
852 size_t subjectOffset,
853 bool skipUTF8Validation)
const;
856 template <
class Vector>
857 void namedSubpatternsImp(Vector *result)
const;
883 template <
class STRING>
884 int replaceImp(STRING *result,
889 bool skipUTF8Validation)
const;
1025 size_t *errorOffset,
1060 template <
class STRING>
1063#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1068 size_t *errorOffset,
1126 size_t subjectOffset = 0)
const;
1145 size_t subjectLength,
1146 size_t subjectOffset = 0)
const;
1166 const char *subject,
1167 size_t subjectLength,
1168 size_t subjectOffset = 0)
const;
1170 const char *subject,
1171 size_t subjectLength,
1172 size_t subjectOffset = 0)
const;
1191 size_t subjectOffset = 0)
const;
1227 const char *subject,
1228 size_t subjectLength,
1229 size_t subjectOffset = 0)
1232 const char *subject,
1233 size_t subjectLength,
1234 size_t subjectOffset = 0)
1239 size_t subjectOffset = 0)
const;
1240 int match(std::vector<bsl::string_view> *result,
1242 size_t subjectOffset = 0)
const;
1243#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1244 int match(std::pmr::vector<bsl::string_view> *result,
1246 size_t subjectOffset = 0)
const;
1290 size_t subjectOffset = 0)
const;
1306 size_t subjectLength,
1307 size_t subjectOffset = 0)
const;
1324 const char *subject,
1325 size_t subjectLength,
1326 size_t subjectOffset = 0)
const;
1328 const char *subject,
1329 size_t subjectLength,
1330 size_t subjectOffset = 0)
const;
1346 size_t subjectOffset = 0)
const;
1379 const char *subject,
1380 size_t subjectLength,
1381 size_t subjectOffset = 0)
1384 const char *subject,
1385 size_t subjectLength,
1386 size_t subjectOffset = 0)
1391 size_t subjectOffset = 0)
1395 size_t subjectOffset = 0)
1397#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1398 int matchRaw(std::pmr::vector<bsl::string_view> *result,
1400 size_t subjectOffset = 0)
1433 std::vector<std::pair<bsl::string_view, int> > *result)
const;
1434#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1436 std::pmr::vector<std::pair<bsl::string_view, int> > *result)
const;
1459 size_t options = 0)
const;
1464 size_t options = 0)
const;
1465#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1466 int replace(std::pmr::string *result,
1470 size_t options = 0)
const;
1502 size_t options = 0)
const;
1507 size_t options = 0)
const;
1508#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1513 size_t options = 0)
const;
1583 pcre2_compile_context_free(d_compileContext_p);
1584 pcre2_general_context_free(d_pcre2Context_p);
1588template <
class STRING>
1591#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1596 size_t *errorOffset,
1597 const char *pattern,
1599 size_t jitStackSize)
1601 const int k_BUFFER_LEN = 256;
1602 char buffer[k_BUFFER_LEN] = {0};
1605 int ret = prepareImp(&buffer[0],
1614 errorMessage->assign(&buffer[0]);
1617 *errorOffset = offset;
1628 return d_depthLimit;
1640 return (0 != d_patternCode_p);
1646 return d_jitStackSize;
Definition bdlpcre_regex.h:766
void namedSubpatterns(std::vector< std::pair< bsl::string_view, int > > *result) const
int matchRaw(std::vector< bsl::string_view > *result, const bsl::string_view &subject, size_t subjectOffset=0) const
int setDepthLimit(int depthLimit)
int match(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(bsl::vector< bsl::string_view > *result, const bsl::string_view &subject, size_t subjectOffset=0) const
static const size_t k_INVALID_OFFSET
Definition bdlpcre_regex.h:981
int match(bsl::pair< size_t, size_t > *result, 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
static bool isJitAvailable()
int matchRaw(bsl::string_view *result, const bsl::string_view &subject, size_t subjectOffset=0) const
int depthLimit() const
Definition bdlpcre_regex.h:1626
@ k_REPLACE_UNSET_EMPTY
Definition bdlpcre_regex.h:930
@ k_REPLACE_UNKNOWN_UNSET
Definition bdlpcre_regex.h:928
@ k_REPLACE_GLOBAL
Definition bdlpcre_regex.h:922
@ k_REPLACE_EXTENDED
Definition bdlpcre_regex.h:925
@ k_REPLACE_LITERAL
Definition bdlpcre_regex.h:920
int prepare(bsl::nullptr_t errorMessage, size_t *errorOffset, const char *pattern, int flags=0, size_t jitStackSize=0)
int replaceRaw(bsl::string *result, int *errorOffset, const bsl::string_view &subject, const bsl::string_view &replacement, size_t options=0) const
int matchRaw(bsl::string_view *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
BSLMF_NESTED_TRAIT_DECLARATION(RegEx, bslma::UsesBslmaAllocator)
RegEx(bslma::Allocator *basicAllocator=0)
~RegEx()
Destroy this regular-expression object.
Definition bdlpcre_regex.h:1580
int match(bsl::vector< bsl::string_view > *result, const bsl::string_view &subject, size_t subjectOffset=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 match(std::vector< bsl::string_view > *result, const bsl::string_view &subject, size_t subjectOffset=0) const
int flags() const
Definition bdlpcre_regex.h:1632
static int defaultDepthLimit()
Return the process-wide default evaluation recursion depth limit.
Definition bdlpcre_regex.h:1563
int match(bsl::vector< bslstl::StringRef > *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
const bsl::string & pattern() const
Definition bdlpcre_regex.h:1650
int match(const char *subject, size_t subjectLength, 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
size_t jitStackSize() const
Definition bdlpcre_regex.h:1644
static int setDefaultDepthLimit(int depthLimit)
Definition bdlpcre_regex.h:1569
void namedSubpatterns(bsl::vector< bsl::pair< bsl::string_view, int > > *result) 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::string_view *result, const char *subject, size_t subjectLength, size_t subjectOffset=0) const
int match(const bsl::string_view &subject, size_t subjectOffset=0) const
int subpatternIndex(const char *name) const
bool isPrepared() const
Definition bdlpcre_regex.h:1638
@ k_FLAG_JIT
Definition bdlpcre_regex.h:909
@ k_FLAG_CASELESS
Definition bdlpcre_regex.h:900
@ k_FLAG_DUPNAMES
Definition bdlpcre_regex.h:912
@ k_FLAG_MULTILINE
Definition bdlpcre_regex.h:905
@ k_FLAG_UTF8
Definition bdlpcre_regex.h:907
@ k_FLAG_DOTMATCHESALL
Definition bdlpcre_regex.h:902
int replace(bsl::string *result, int *errorOffset, const bsl::string_view &subject, const bsl::string_view &replacement, size_t options=0) const
int numSubpatterns() const
int matchRaw(const char *subject, size_t subjectLength, size_t subjectOffset=0) const
@ k_STATUS_UTF8_TRUNCATED_CHARACTER_FAILURE
the UTF-8 string ends with a truncated UTF-8 character
Definition bdlpcre_regex.h:951
@ k_STATUS_DEPTH_LIMIT_FAILURE
depthLimit() was exceeded
Definition bdlpcre_regex.h:944
@ k_STATUS_UTF8_5_OR_6_BYTES_CHARACTER_FAILURE
a UTF-8 character is either 5 or 6 bytes long
Definition bdlpcre_regex.h:958
@ k_STATUS_UTF8_4_BYTES_CHARACTER_RANGE_FAILURE
a 4-byte UTF-8 character has a value greater than 0x10ffff
Definition bdlpcre_regex.h:961
@ k_STATUS_SUCCESS
successful completion of the operation
Definition bdlpcre_regex.h:938
@ k_STATUS_UTF8_FIRST_BYTE_WRONG_VALUE_FAILURE
the first byte of a UTF-8 character has the value 0xfe or 0xff
Definition bdlpcre_regex.h:976
@ k_STATUS_NO_MATCH
the subject string did not match the pattern
Definition bdlpcre_regex.h:941
@ k_STATUS_UTF8_SIGNIFICANT_BITS_VALUE_FAILURE
Definition bdlpcre_regex.h:955
@ k_STATUS_UTF8_3_BYTES_CHARACTER_RANGE_FAILURE
Definition bdlpcre_regex.h:965
@ k_STATUS_UTF8_FIRST_BYTE_SIGNIFICANT_BITS_FAILURE
Definition bdlpcre_regex.h:973
@ k_STATUS_UTF8_OVERLONG_CHARACTER_FAILURE
Definition bdlpcre_regex.h:969
@ k_STATUS_JIT_STACK_LIMIT_FAILURE
Definition bdlpcre_regex.h:948
int replace(std::string *result, int *errorOffset, const bsl::string_view &subject, const bsl::string_view &replacement, size_t options=0) const
Definition bslstl_stringview.h:441
Definition bslstl_string.h:1281
Definition bslstl_pair.h:1210
Definition bslstl_vector.h:1025
Definition bslma_allocator.h:457
Definition bslma_managedptr.h:1182
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlpcre_regex.h:748
BloombergLP::bsls::Nullptr_Impl::Type nullptr_t
Definition bsls_nullptr.h:281
Definition bslmf_enableif.h:525
Definition bslmf_issame.h:146
Definition bslma_usesbslmaallocator.h:343
static void setIntRelaxed(AtomicTypes::Int *atomicInt, int value)
Definition bsls_atomicoperations.h:1552
static int getIntRelaxed(AtomicTypes::Int const *atomicInt)
Definition bsls_atomicoperations.h:1534