Skip to content

Commit

Permalink
pcre2: Version 10.44 (#4478) (#4678)
Browse files Browse the repository at this point in the history
* update(pcre2): Version 10.44 (#4478)

* update(pcre2): Add new file to VS project files (version 10.44) (#4478)

* fix(RegEx): Use generic pcre2 function names (without suffix _8).

* update(pcre2): Fix configuration (define PCRE2_STATIC) (#4478)
  • Loading branch information
matejk authored Oct 3, 2024
1 parent 04fe04e commit f3975eb
Show file tree
Hide file tree
Showing 36 changed files with 5,990 additions and 4,410 deletions.
1 change: 1 addition & 0 deletions Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ else()
POCO_SOURCES(SRCS pcre2
src/pcre2_auto_possess.c
src/pcre2_chartables.c
src/pcre2_chkdint.c
src/pcre2_compile.c
src/pcre2_config.c
src/pcre2_context.c
Expand Down
1 change: 1 addition & 0 deletions Foundation/Foundation_vs160.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@
<ClCompile Include="src\PatternFormatter.cpp" />
<ClCompile Include="src\pcre2_auto_possess.c" />
<ClCompile Include="src\pcre2_chartables.c" />
<ClCompile Include="src\pcre2_chkdint.c" />
<ClCompile Include="src\pcre2_compile.c" />
<ClCompile Include="src\pcre2_config.c" />
<ClCompile Include="src\pcre2_context.c" />
Expand Down
3 changes: 3 additions & 0 deletions Foundation/Foundation_vs160.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,9 @@
<ClCompile Include="src\pcre2_chartables.c">
<Filter>RegularExpression\PCRE2 Source Files</Filter>
</ClCompile>
<ClCompile Include="src\pcre2_chkdint.c">
<Filter>RegularExpression\PCRE2 Source Files</Filter>
</ClCompile>
<ClCompile Include="src\pcre2_compile.c">
<Filter>RegularExpression\PCRE2 Source Files</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions Foundation/Foundation_vs170.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,7 @@
<ClCompile Include="src\PatternFormatter.cpp" />
<ClCompile Include="src\pcre2_auto_possess.c" />
<ClCompile Include="src\pcre2_chartables.c" />
<ClCompile Include="src\pcre2_chkdint.c" />
<ClCompile Include="src\pcre2_compile.c" />
<ClCompile Include="src\pcre2_config.c" />
<ClCompile Include="src\pcre2_context.c" />
Expand Down
3 changes: 3 additions & 0 deletions Foundation/Foundation_vs170.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,9 @@
<ClCompile Include="src\pcre2_chartables.c">
<Filter>RegularExpression\PCRE2 Source Files</Filter>
</ClCompile>
<ClCompile Include="src\pcre2_chkdint.c">
<Filter>RegularExpression\PCRE2 Source Files</Filter>
</ClCompile>
<ClCompile Include="src\pcre2_compile.c">
<Filter>RegularExpression\PCRE2 Source Files</Filter>
</ClCompile>
Expand Down
2 changes: 1 addition & 1 deletion Foundation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ objects = ArchiveStrategy Ascii ASCIIEncoding AsyncChannel AsyncNotificationCent
zlib_objects = adler32 compress crc32 deflate \
infback inffast inflate inftrees trees zutil

pcre_objects = pcre2_auto_possess pcre2_chartables pcre2_compile pcre2_config \
pcre_objects = pcre2_auto_possess pcre2_chartables pcre2_chkdint pcre2_compile pcre2_config \
pcre2_context pcre2_convert pcre2_dfa_match pcre2_error pcre2_extuni \
pcre2_find_bracket pcre2_jit_compile pcre2_maketables pcre2_match \
pcre2_match_data pcre2_newline pcre2_ord2utf pcre2_pattern_info \
Expand Down
60 changes: 30 additions & 30 deletions Foundation/src/RegularExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ namespace
class MatchData
{
public:
MatchData(pcre2_code_8* code):
_match(pcre2_match_data_create_from_pattern_8(reinterpret_cast<pcre2_code_8*>(code), nullptr))
MatchData(pcre2_code* code):
_match(pcre2_match_data_create_from_pattern(reinterpret_cast<pcre2_code*>(code), nullptr))
{
if (!_match) throw Poco::RegularExpressionException("cannot create match data");
}

~MatchData()
{
if (_match) pcre2_match_data_free_8(_match);
if (_match) pcre2_match_data_free(_match);
}

std::uint32_t count() const
{
return pcre2_get_ovector_count_8(_match);
return pcre2_get_ovector_count(_match);
}

const PCRE2_SIZE* data() const
{
return pcre2_get_ovector_pointer_8(_match);
return pcre2_get_ovector_pointer(_match);
}

operator pcre2_match_data_8*()
operator pcre2_match_data*()
{
return _match;
}

private:
pcre2_match_data_8* _match;
pcre2_match_data* _match;
};
}

Expand All @@ -72,57 +72,57 @@ RegularExpression::RegularExpression(const std::string& pattern, int options, bo
unsigned nameEntrySize;
unsigned char* nameTable;

pcre2_compile_context_8* context = pcre2_compile_context_create_8(nullptr);
pcre2_compile_context* context = pcre2_compile_context_create(nullptr);
if (!context) throw Poco::RegularExpressionException("cannot create compile context");

if (options & RE_NEWLINE_LF)
pcre2_set_newline_8(context, PCRE2_NEWLINE_LF);
pcre2_set_newline(context, PCRE2_NEWLINE_LF);
else if (options & RE_NEWLINE_CRLF)
pcre2_set_newline_8(context, PCRE2_NEWLINE_CRLF);
pcre2_set_newline(context, PCRE2_NEWLINE_CRLF);
else if (options & RE_NEWLINE_ANY)
pcre2_set_newline_8(context, PCRE2_NEWLINE_ANY);
pcre2_set_newline(context, PCRE2_NEWLINE_ANY);
else if (options & RE_NEWLINE_ANYCRLF)
pcre2_set_newline_8(context, PCRE2_NEWLINE_ANYCRLF);
pcre2_set_newline(context, PCRE2_NEWLINE_ANYCRLF);
else // default RE_NEWLINE_CR
pcre2_set_newline_8(context, PCRE2_NEWLINE_CR);
pcre2_set_newline(context, PCRE2_NEWLINE_CR);

_pcre = pcre2_compile_8(reinterpret_cast<const PCRE2_SPTR>(pattern.c_str()), pattern.length(), compileOptions(options), &errorCode, &errorOffset, context);
pcre2_compile_context_free_8(context);
_pcre = pcre2_compile(reinterpret_cast<const PCRE2_SPTR>(pattern.c_str()), pattern.length(), compileOptions(options), &errorCode, &errorOffset, context);
pcre2_compile_context_free(context);

if (!_pcre)
{
PCRE2_UCHAR buffer[256];
pcre2_get_error_message_8(errorCode, buffer, sizeof(buffer));
pcre2_get_error_message(errorCode, buffer, sizeof(buffer));
std::ostringstream msg;
msg << reinterpret_cast<char*>(buffer) << " (at offset " << errorOffset << ")";
throw RegularExpressionException(msg.str());
}

pcre2_pattern_info_8(reinterpret_cast<pcre2_code_8*>(_pcre), PCRE2_INFO_NAMECOUNT, &nameCount);
pcre2_pattern_info_8(reinterpret_cast<pcre2_code_8*>(_pcre), PCRE2_INFO_NAMEENTRYSIZE, &nameEntrySize);
pcre2_pattern_info_8(reinterpret_cast<pcre2_code_8*>(_pcre), PCRE2_INFO_NAMETABLE, &nameTable);
pcre2_pattern_info(reinterpret_cast<pcre2_code*>(_pcre), PCRE2_INFO_NAMECOUNT, &nameCount);
pcre2_pattern_info(reinterpret_cast<pcre2_code*>(_pcre), PCRE2_INFO_NAMEENTRYSIZE, &nameEntrySize);
pcre2_pattern_info(reinterpret_cast<pcre2_code*>(_pcre), PCRE2_INFO_NAMETABLE, &nameTable);

for (int i = 0; i < nameCount; i++)
{
unsigned char* group = nameTable + 2 + (nameEntrySize * i);
int n = pcre2_substring_number_from_name_8(reinterpret_cast<pcre2_code_8*>(_pcre), group);
int n = pcre2_substring_number_from_name(reinterpret_cast<pcre2_code*>(_pcre), group);
_groups[n] = std::string(reinterpret_cast<char*>(group));
}
}


RegularExpression::~RegularExpression()
{
if (_pcre) pcre2_code_free_8(reinterpret_cast<pcre2_code_8*>(_pcre));
if (_pcre) pcre2_code_free(reinterpret_cast<pcre2_code*>(_pcre));
}


int RegularExpression::match(const std::string& subject, std::string::size_type offset, Match& mtch, int options) const
{
poco_assert (offset <= subject.length());

MatchData matchData(reinterpret_cast<pcre2_code_8*>(_pcre));
int rc = pcre2_match_8(reinterpret_cast<pcre2_code_8*>(_pcre), reinterpret_cast<const PCRE2_SPTR>(subject.c_str()), subject.size(), offset, matchOptions(options), matchData, nullptr);
MatchData matchData(reinterpret_cast<pcre2_code*>(_pcre));
int rc = pcre2_match(reinterpret_cast<pcre2_code*>(_pcre), reinterpret_cast<const PCRE2_SPTR>(subject.c_str()), subject.size(), offset, matchOptions(options), matchData, nullptr);
if (rc == PCRE2_ERROR_NOMATCH)
{
mtch.offset = std::string::npos;
Expand All @@ -140,7 +140,7 @@ int RegularExpression::match(const std::string& subject, std::string::size_type
else if (rc < 0)
{
PCRE2_UCHAR buffer[256];
pcre2_get_error_message_8(rc, buffer, sizeof(buffer));
pcre2_get_error_message(rc, buffer, sizeof(buffer));
throw RegularExpressionException(std::string(reinterpret_cast<char*>(buffer)));
}
const PCRE2_SIZE* ovec = matchData.data();
Expand All @@ -156,8 +156,8 @@ int RegularExpression::match(const std::string& subject, std::string::size_type

matches.clear();

MatchData matchData(reinterpret_cast<pcre2_code_8*>(_pcre));
int rc = pcre2_match_8(reinterpret_cast<pcre2_code_8*>(_pcre), reinterpret_cast<const PCRE2_SPTR>(subject.c_str()), subject.size(), offset, options & 0xFFFF, matchData, nullptr);
MatchData matchData(reinterpret_cast<pcre2_code*>(_pcre));
int rc = pcre2_match(reinterpret_cast<pcre2_code*>(_pcre), reinterpret_cast<const PCRE2_SPTR>(subject.c_str()), subject.size(), offset, options & 0xFFFF, matchData, nullptr);
if (rc == PCRE2_ERROR_NOMATCH)
{
return 0;
Expand All @@ -173,7 +173,7 @@ int RegularExpression::match(const std::string& subject, std::string::size_type
else if (rc < 0)
{
PCRE2_UCHAR buffer[256];
pcre2_get_error_message_8(rc, buffer, sizeof(buffer));
pcre2_get_error_message(rc, buffer, sizeof(buffer));
throw RegularExpressionException(std::string(reinterpret_cast<char*>(buffer)));
}
matches.reserve(rc);
Expand Down Expand Up @@ -279,8 +279,8 @@ std::string::size_type RegularExpression::substOne(std::string& subject, std::st
{
if (offset >= subject.length()) return std::string::npos;

MatchData matchData(reinterpret_cast<pcre2_code_8*>(_pcre));
int rc = pcre2_match_8(reinterpret_cast<pcre2_code_8*>(_pcre), reinterpret_cast<const PCRE2_SPTR>(subject.c_str()), subject.size(), offset, matchOptions(options), matchData, nullptr);
MatchData matchData(reinterpret_cast<pcre2_code*>(_pcre));
int rc = pcre2_match(reinterpret_cast<pcre2_code*>(_pcre), reinterpret_cast<const PCRE2_SPTR>(subject.c_str()), subject.size(), offset, matchOptions(options), matchData, nullptr);
if (rc == PCRE2_ERROR_NOMATCH)
{
return std::string::npos;
Expand All @@ -296,7 +296,7 @@ std::string::size_type RegularExpression::substOne(std::string& subject, std::st
else if (rc < 0)
{
PCRE2_UCHAR buffer[256];
pcre2_get_error_message_8(rc, buffer, sizeof(buffer));
pcre2_get_error_message(rc, buffer, sizeof(buffer));
throw RegularExpressionException(std::string(reinterpret_cast<char*>(buffer)));
}
const PCRE2_SIZE* ovec = matchData.data();
Expand Down
2 changes: 1 addition & 1 deletion Foundation/src/Unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void Unicode::properties(int ch, CharacterProperties& props)
{
if (ch > UCP_MAX_CODEPOINT) ch = 0;
const ucd_record* ucd = GET_UCD(ch);
props.category = static_cast<CharacterCategory>(PRIV(ucp_gentype_8)[ucd->chartype]);
props.category = static_cast<CharacterCategory>(PRIV(ucp_gentype)[ucd->chartype]);
props.type = static_cast<CharacterType>(ucd->chartype);
props.script = static_cast<Script>(ucd->script);
}
Expand Down
35 changes: 26 additions & 9 deletions Foundation/src/pcre2.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* This is the public header file for the PCRE library, second API, to be
#included by applications that call PCRE2 functions.
Copyright (c) 2016-2021 University of Cambridge
Copyright (c) 2016-2024 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -42,9 +42,9 @@ POSSIBILITY OF SUCH DAMAGE.
/* The current PCRE version information. */

#define PCRE2_MAJOR 10
#define PCRE2_MINOR 42
#define PCRE2_PRERELEASE
#define PCRE2_DATE 2022-12-11
#define PCRE2_MINOR 44
#define PCRE2_PRERELEASE
#define PCRE2_DATE 2024-06-07

/* When an application links to a PCRE DLL in Windows, the symbols that are
imported have to be identified as such. When building PCRE2, the appropriate
Expand Down Expand Up @@ -153,6 +153,12 @@ D is inspected during pcre2_dfa_match() execution
#define PCRE2_EXTRA_ESCAPED_CR_IS_LF 0x00000010u /* C */
#define PCRE2_EXTRA_ALT_BSUX 0x00000020u /* C */
#define PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK 0x00000040u /* C */
#define PCRE2_EXTRA_CASELESS_RESTRICT 0x00000080u /* C */
#define PCRE2_EXTRA_ASCII_BSD 0x00000100u /* C */
#define PCRE2_EXTRA_ASCII_BSS 0x00000200u /* C */
#define PCRE2_EXTRA_ASCII_BSW 0x00000400u /* C */
#define PCRE2_EXTRA_ASCII_POSIX 0x00000800u /* C */
#define PCRE2_EXTRA_ASCII_DIGIT 0x00001000u /* C */

/* These are for pcre2_jit_compile(). */

Expand Down Expand Up @@ -180,11 +186,12 @@ pcre2_jit_match() ignores the latter since it bypasses all sanity checks). */
#define PCRE2_SUBSTITUTE_UNSET_EMPTY 0x00000400u /* pcre2_substitute() only */
#define PCRE2_SUBSTITUTE_UNKNOWN_UNSET 0x00000800u /* pcre2_substitute() only */
#define PCRE2_SUBSTITUTE_OVERFLOW_LENGTH 0x00001000u /* pcre2_substitute() only */
#define PCRE2_NO_JIT 0x00002000u /* Not for pcre2_dfa_match() */
#define PCRE2_NO_JIT 0x00002000u /* not for pcre2_dfa_match() */
#define PCRE2_COPY_MATCHED_SUBJECT 0x00004000u
#define PCRE2_SUBSTITUTE_LITERAL 0x00008000u /* pcre2_substitute() only */
#define PCRE2_SUBSTITUTE_MATCHED 0x00010000u /* pcre2_substitute() only */
#define PCRE2_SUBSTITUTE_REPLACEMENT_ONLY 0x00020000u /* pcre2_substitute() only */
#define PCRE2_DISABLE_RECURSELOOP_CHECK 0x00040000u /* not for pcre2_dfa_match() or pcre2_jit_match() */

/* Options for pcre2_pattern_convert(). */

Expand Down Expand Up @@ -399,6 +406,7 @@ released, the numbers must not be changed. */
#define PCRE2_ERROR_CONVERT_SYNTAX (-64)
#define PCRE2_ERROR_INTERNAL_DUPMATCH (-65)
#define PCRE2_ERROR_DFA_UINVALID_UTF (-66)
#define PCRE2_ERROR_INVALIDOFFSET (-67)


/* Request types for pcre2_pattern_info() */
Expand Down Expand Up @@ -575,7 +583,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION pcre2_config(uint32_t, void *);
PCRE2_EXP_DECL pcre2_general_context *PCRE2_CALL_CONVENTION \
pcre2_general_context_copy(pcre2_general_context *); \
PCRE2_EXP_DECL pcre2_general_context *PCRE2_CALL_CONVENTION \
pcre2_general_context_create(void *(*)(PCRE2_SIZE, void *), \
pcre2_general_context_create(void *(*)(size_t, void *), \
void (*)(void *, void *), void *); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_general_context_free(pcre2_general_context *);
Expand All @@ -595,6 +603,10 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_compile_extra_options(pcre2_compile_context *, uint32_t); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_max_pattern_length(pcre2_compile_context *, PCRE2_SIZE); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_max_pattern_compiled_length(pcre2_compile_context *, PCRE2_SIZE); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_max_varlookbehind(pcre2_compile_context *, uint32_t); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_newline(pcre2_compile_context *, uint32_t); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
Expand Down Expand Up @@ -628,7 +640,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_recursion_limit(pcre2_match_context *, uint32_t); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_set_recursion_memory_management(pcre2_match_context *, \
void *(*)(PCRE2_SIZE, void *), void (*)(void *, void *), void *);
void *(*)(size_t, void *), void (*)(void *, void *), void *);

#define PCRE2_CONVERT_CONTEXT_FUNCTIONS \
PCRE2_EXP_DECL pcre2_convert_context *PCRE2_CALL_CONVENTION \
Expand Down Expand Up @@ -687,6 +699,8 @@ PCRE2_EXP_DECL PCRE2_SPTR PCRE2_CALL_CONVENTION \
pcre2_get_mark(pcre2_match_data *); \
PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \
pcre2_get_match_data_size(pcre2_match_data *); \
PCRE2_EXP_DECL PCRE2_SIZE PCRE2_CALL_CONVENTION \
pcre2_get_match_data_heapframes_size(pcre2_match_data *); \
PCRE2_EXP_DECL uint32_t PCRE2_CALL_CONVENTION \
pcre2_get_ovector_count(pcre2_match_data *); \
PCRE2_EXP_DECL PCRE2_SIZE *PCRE2_CALL_CONVENTION \
Expand Down Expand Up @@ -722,7 +736,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_substring_number_from_name(const pcre2_code *, PCRE2_SPTR); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_substring_list_free(PCRE2_SPTR *); \
pcre2_substring_list_free(PCRE2_UCHAR **); \
PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
pcre2_substring_list_get(pcre2_match_data *, PCRE2_UCHAR ***, PCRE2_SIZE **);

Expand Down Expand Up @@ -771,7 +785,7 @@ PCRE2_EXP_DECL int PCRE2_CALL_CONVENTION \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_jit_free_unused_memory(pcre2_general_context *); \
PCRE2_EXP_DECL pcre2_jit_stack *PCRE2_CALL_CONVENTION \
pcre2_jit_stack_create(PCRE2_SIZE, PCRE2_SIZE, pcre2_general_context *); \
pcre2_jit_stack_create(size_t, size_t, pcre2_general_context *); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
pcre2_jit_stack_assign(pcre2_match_context *, pcre2_jit_callback, void *); \
PCRE2_EXP_DECL void PCRE2_CALL_CONVENTION \
Expand Down Expand Up @@ -851,6 +865,7 @@ pcre2_compile are called by application code. */
#define pcre2_general_context_free PCRE2_SUFFIX(pcre2_general_context_free_)
#define pcre2_get_error_message PCRE2_SUFFIX(pcre2_get_error_message_)
#define pcre2_get_mark PCRE2_SUFFIX(pcre2_get_mark_)
#define pcre2_get_match_data_heapframes_size PCRE2_SUFFIX(pcre2_get_match_data_heapframes_size_)
#define pcre2_get_match_data_size PCRE2_SUFFIX(pcre2_get_match_data_size_)
#define pcre2_get_ovector_pointer PCRE2_SUFFIX(pcre2_get_ovector_pointer_)
#define pcre2_get_ovector_count PCRE2_SUFFIX(pcre2_get_ovector_count_)
Expand Down Expand Up @@ -886,7 +901,9 @@ pcre2_compile are called by application code. */
#define pcre2_set_glob_separator PCRE2_SUFFIX(pcre2_set_glob_separator_)
#define pcre2_set_heap_limit PCRE2_SUFFIX(pcre2_set_heap_limit_)
#define pcre2_set_match_limit PCRE2_SUFFIX(pcre2_set_match_limit_)
#define pcre2_set_max_varlookbehind PCRE2_SUFFIX(pcre2_set_max_varlookbehind_)
#define pcre2_set_max_pattern_length PCRE2_SUFFIX(pcre2_set_max_pattern_length_)
#define pcre2_set_max_pattern_compiled_length PCRE2_SUFFIX(pcre2_set_max_pattern_compiled_length_)
#define pcre2_set_newline PCRE2_SUFFIX(pcre2_set_newline_)
#define pcre2_set_parens_nest_limit PCRE2_SUFFIX(pcre2_set_parens_nest_limit_)
#define pcre2_set_offset_limit PCRE2_SUFFIX(pcre2_set_offset_limit_)
Expand Down
Loading

0 comments on commit f3975eb

Please sign in to comment.