Skip to content

Commit 65719e6

Browse files
committed
options flags update and string_view support
1 parent 2ef72f7 commit 65719e6

19 files changed

Lines changed: 422 additions & 368 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.30)
2-
project(pcre2cpp VERSION 1.2.1 LANGUAGES CXX)
2+
project(pcre2cpp VERSION 1.2.2 LANGUAGES CXX)
33

44
option(BUILD_SHARED_LIBS "Build shared library" OFF)
55
option(PCRE2CPP_BUILD_TESTS "Build tests" OFF)

cmake/coverage_report.cmake

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function(setup_coverage_report)
8282
# GET BINARY_DIR OF TARGET
8383
get_target_property(TARGET_BINARY_DIR ${TARGET_NAME} BINARY_DIR)
8484
# GET EXE FILE
85-
set(EXE_FILE "${TARGET_BINARY_DIR}/${TARGET_NAME}.exe")
85+
set(EXE_FILE "$<TARGET_FILE:${TARGET_NAME}>")
8686

8787
list(APPEND TARGETS_EXECS ${EXE_FILE})
8888

@@ -95,9 +95,8 @@ function(setup_coverage_report)
9595

9696
# ADD COMMAND
9797
add_custom_command(TARGET ${COVERAGE_TARGET_NAME} POST_BUILD
98-
COMMAND set LLVM_PROFILE_FILE=${TARGET_PROFRAW}
99-
COMMAND ${EXE_FILE}
100-
COMMENT "Running program to generate ${PROFRAW_TESTS}"
98+
COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${TARGET_PROFRAW} ${EXE_FILE}
99+
COMMENT "Running ${TARGET_NAME} to generate ${PROFRAW_TESTS}"
101100
WORKING_DIRECTORY ${TARGET_BINARY_DIR}
102101
VERBATIM
103102
)
@@ -116,14 +115,18 @@ function(setup_coverage_report)
116115
get_target_property(TEST_TARGET_SOURCE_DIR ${COVERAGE_TEST_TARGET} SOURCE_DIR)
117116
file(RELATIVE_PATH TEST_TARGET_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ${TEST_TARGET_SOURCE_DIR})
118117
file(TO_NATIVE_PATH ${TEST_TARGET_SOURCE_DIR} TEST_TARGET_SOURCE_DIR)
119-
set(TEST_FILES_REGEX ".*[\\\\|\\\/]${TEST_TARGET_SOURCE_DIR}[\\\\|\\\/].*")
120-
121-
list(GET TARGETS_EXECS 0 TEST_EXE)
118+
set(TEST_FILES_REGEX ".*[\\\\\\\/]${TEST_TARGET_SOURCE_DIR}[\\\\\\\/].*")
119+
122120
add_custom_command(TARGET ${COVERAGE_TARGET_NAME} POST_BUILD
123-
COMMAND ${LLVM_COV} show ${TEST_EXE} -instr-profile=${PROFDATA_FILE}
124-
-format=${COVERAGE_FORMAT} -output-dir=${COVERAGE_OUTPUT_DIR} -ignore-filename-regex=${TEST_FILES_REGEX} -show-mcdc -show-line-counts
125-
-show-expansions -show-instantiations -show-regions -show-line-counts-or-regions -show-directory-coverage -use-color --show-branches percent
126-
COMMENT "Generating report..."
121+
COMMAND ${LLVM_COV} show ${TEST_EXE}
122+
-instr-profile=${PROFDATA_FILE}
123+
-format=${COVERAGE_FORMAT}
124+
-output-dir=${COVERAGE_OUTPUT_DIR}
125+
-ignore-filename-regex=${TEST_FILES_REGEX}
126+
-show-mcdc -show-line-counts -show-expansions
127+
-show-instantiations -show-regions -show-line-counts-or-regions
128+
-show-directory-coverage -use-color --show-branches percent
129+
COMMENT "Generating '${COVERAGE_FORMAT}' report..."
127130
WORKING_DIRECTORY ${COVERAGE_OUTPUT_DIR}
128131
VERBATIM
129132
)

cmake/third_party.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ include(${CPM_DOWNLOAD_LOCATION})
2525
# Add pcre2 library
2626
if (NOT ${PCRE2CPP_USE_EXTERNAL_PCRE2})
2727
CPMAddPackage(
28-
URI "gh:PCRE2Project/pcre2#pcre2-10.44"
28+
URI "gh:PCRE2Project/pcre2#pcre2-10.47"
2929
OPTIONS "PCRE2_BUILD_PCRE2_8 ON"
3030
"PCRE2_BUILD_PCRE2_16 ON"
3131
"PCRE2_BUILD_PCRE2_32 ON"
@@ -46,11 +46,13 @@ set(PCRE2_NEWLINE "ANY")
4646

4747
if (NOT ${PCRE2CPP_USE_EXTERNAL_MSTD})
4848
CPMAddPackage(
49-
URI "gh:maipa01/mstd#v1.5.0"
49+
URI "gh:maipa01/mstd#v1.5.1"
5050
OPTIONS "MSTD_ENABLE_CXX20 ${PCRE2CPP_ENABLE_CXX20}"
51+
"MSTD_DISABLE_ASSERT_ON_RELEASE ${PCRE2CPP_DISABLE_ASSERT_ON_RELEASE}"
5152
)
5253
else()
5354
set(MSTD_ENABLE_CXX20 ${PCRE2CPP_ENABLE_CXX20})
55+
set(MSTD_DISABLE_ASSERT_ON_RELEASE ${PCRE2CPP_DISABLE_ASSERT_ON_RELEASE})
5456
endif()
5557

5658
if(PCRE2CPP_BUILD_TESTS OR PCRE2CPP_BUILD_COVERAGE)

make_single_header.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@echo off
2-
".\tools\one header maker\one_header_maker.exe" ".\pcre2cpp\include\pcre2cpp\pcre2cpp.hpp" ".\pcre2cpp\pcre2cpp.hpp"
2+
python ".\tools\one header maker\one_header_maker.py" ".\pcre2cpp\include\pcre2cpp\pcre2cpp.hpp" ".\pcre2cpp\pcre2cpp.hpp"

pcre2cpp/include/pcre2cpp/config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* @brief pcre2cpp version patch number
5353
* @ingroup pcre2cpp
5454
*/
55-
#define PCRE2CPP_VERSION_PATCH 1
55+
#define PCRE2CPP_VERSION_PATCH 2
5656

5757
/**
5858
* @brief stringify helper
@@ -95,7 +95,7 @@
9595
* @brief pcre2cpp last update day
9696
* @ingroup pcre2cpp
9797
*/
98-
#define PCRE2CPP_LAST_UPDATE_DAY 02
98+
#define PCRE2CPP_LAST_UPDATE_DAY 04
9999
/**
100100
* @brief pcre2cpp last update month
101101
* @ingroup pcre2cpp

pcre2cpp/include/pcre2cpp/exceptions/exceptions.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ namespace pcre2cpp {
3636
using _uchar_type = typename _pcre2_data_t::uchar_type;
3737
using _char_type = typename _pcre2_data_t::string_char_type;
3838

39-
_uchar_type error_message[256];
40-
if (const int size = _pcre2_data_t::get_error_message(error_code, error_message, 256); size != PCRE2_ERROR_BADDATA) {
41-
return _string_type(reinterpret_cast<_char_type*>(error_message), 256);
39+
_uchar_type error_message[120];
40+
if (const int size = _pcre2_data_t::get_error_message(error_code, error_message, 120); size != PCRE2_ERROR_BADDATA) {
41+
return _string_type(reinterpret_cast<_char_type*>(error_message), 120);
4242
}
4343
return _string_type();
4444
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* pcre2cpp - PCRE2 cpp wrapper
3+
*
4+
* Licensed under the BSD 3-Clause License with Attribution Requirement.
5+
* See the LICENSE file for details: https://github.com/MAIPA01/pcre2cpp/blob/main/LICENSE
6+
*
7+
* Copyright (c) 2025, Patryk Antosik (MAIPA01)
8+
*
9+
* PCRE2 library included in this project:
10+
* Copyright (c) 2016-2024, University of Cambridge.
11+
*
12+
* See the LICENSE_PCRE2 file for details: https://github.com/MAIPA01/pcre2cpp/blob/main/LICENSE_PCRE2
13+
*/
14+
#pragma once
15+
#ifndef _PCRE2CPP_MATCH_ERROR_CODES_HPP_
16+
#define _PCRE2CPP_MATCH_ERROR_CODES_HPP_
17+
18+
#include <pcre2cpp/config.hpp>
19+
20+
#if !_PCRE2CPP_HAS_CXX17
21+
_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
22+
#else
23+
24+
#include <pcre2cpp/types.hpp>
25+
26+
namespace pcre2cpp {
27+
enum class match_error_codes : int32_t {
28+
None = 1, // No error (default)
29+
NoMatch = PCRE2_ERROR_NOMATCH, // The subject string did not match the pattern.
30+
Partial = PCRE2_ERROR_PARTIAL, // The subject string did not match, but it did match partially.
31+
BadMagic = PCRE2_ERROR_BADMAGIC, /* PCRE2 stores a 4-byte "magic number" at the start of the compiled code,
32+
to catch the case when it is passed a junk pointer.
33+
This is the error that is returned when the magic number is not present
34+
*/
35+
BadMode =
36+
PCRE2_ERROR_BADMODE, /* This error is given when a compiled pattern is passed
37+
to a function in a library of a different code unit width, for example,
38+
a pattern compiled by the 8-bit library is passed to a 16-bit or 32-bit library function.
39+
*/
40+
BadOffset = PCRE2_ERROR_BADOFFSET, // The value of startoffset was greater than the length of the subject.
41+
BadOption = PCRE2_ERROR_BADOPTION, // An unrecognized bit was set in the options argument.
42+
BadUTFOffset = PCRE2_ERROR_BADUTFOFFSET, /* The UTF code unit sequence that was passed as a subject was checked
43+
and found to be valid (the match_option::NoUTFCheck option was not set),
44+
but the value of startoffset did not point to the beginning of a
45+
UTF character or the end of the subject.
46+
*/
47+
Callout = PCRE2_ERROR_CALLOUT, /* This error is never generated by pcre2_match() itself.
48+
It is provided for use by callout functions that want to cause
49+
pcre2_match() or pcre2_callout_enumerate() to return a distinctive error code.
50+
*/
51+
DepthLimit = PCRE2_ERROR_DEPTHLIMIT, // The nested backtracking depth limit was reached.
52+
HeapLimit = PCRE2_ERROR_HEAPLIMIT, // The heap limit was reached.
53+
Internal =
54+
PCRE2_ERROR_INTERNAL, /* An unexpected internal error has occurred.
55+
This error could be caused by a bug in PCRE2 or by overwriting of the compiled pattern.
56+
*/
57+
JITStackLimit = PCRE2_ERROR_JIT_STACKLIMIT, /* This error is returned when a pattern that was successfully
58+
studied using JIT is being matched, but the memory available
59+
for the just-in-time processing stack is not large enough.
60+
*/
61+
MatchLimit = PCRE2_ERROR_MATCHLIMIT, // The backtracking match limit was reached.
62+
NoMemory = PCRE2_ERROR_NOMEMORY, /* Heap memory is used to remember backtracking points.
63+
This error is given when the memory allocation function (default or custom) fails.
64+
Note that a different error, PCRE2_ERROR_HEAPLIMIT, is given if the amount of memory
65+
needed exceeds the heap limit. match_error_codes::NoMemory is also returned
66+
if match_options_bits::CopyMatchedSubject is set and memory allocation fails.
67+
*/
68+
Null = PCRE2_ERROR_NULL, // Either the code, subject, or match_data argument was passed as nullptr.
69+
RecurseLoop =
70+
PCRE2_ERROR_RECURSELOOP /* This error is returned when pcre2_match() detects a recursion loop within the pattern.
71+
Specifically, it means that either the whole pattern or a capture group has been called
72+
recursively for the second time at the same position in the subject string.
73+
Some simple patterns that might do this are detected and faulted at compile time,
74+
but more complicated cases, in particular mutual recursions between two different groups,
75+
cannot be detected until matching is attempted.
76+
*/
77+
};
78+
} // namespace pcre2cpp
79+
#endif
80+
#endif
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* pcre2cpp - PCRE2 cpp wrapper
3+
*
4+
* Licensed under the BSD 3-Clause License with Attribution Requirement.
5+
* See the LICENSE file for details: https://github.com/MAIPA01/pcre2cpp/blob/main/LICENSE
6+
*
7+
* Copyright (c) 2025, Patryk Antosik (MAIPA01)
8+
*
9+
* PCRE2 library included in this project:
10+
* Copyright (c) 2016-2024, University of Cambridge.
11+
*
12+
* See the LICENSE_PCRE2 file for details: https://github.com/MAIPA01/pcre2cpp/blob/main/LICENSE_PCRE2
13+
*/
14+
#pragma once
15+
#ifndef _PCRE2CPP_REGEX_MATCH_OPTIONS_HPP_
16+
#define _PCRE2CPP_REGEX_MATCH_OPTIONS_HPP_
17+
18+
#include <pcre2cpp/config.hpp>
19+
20+
#if !_PCRE2CPP_HAS_CXX17
21+
_PCRE2CPP_ERROR("This is only available for c++17 and greater!");
22+
#else
23+
24+
#include <pcre2cpp/types.hpp>
25+
26+
namespace pcre2cpp {
27+
enum class match_options_bits : uint32_t {
28+
None = 0u, // No options set (default)
29+
Anchored = PCRE2_ANCHORED, // Match only at the first position
30+
CopyMatchedSubject = PCRE2_COPY_MATCHED_SUBJECT, // On success, make a private subject copy
31+
DisableRecurseLoopCheck = PCRE2_DISABLE_RECURSELOOP_CHECK, // Only useful in rare cases; use with care
32+
EndAnchored = PCRE2_ENDANCHORED, // Pattern can match only at end of subject
33+
NotBOL = PCRE2_NOTBOL, // Subject string is not the beginning of a line
34+
NotEOL = PCRE2_NOTEOL, // Subject string is not the end of a line
35+
NotEmpty = PCRE2_NOTEMPTY, // An empty string is not a valid match
36+
NotEmptyAtStart = PCRE2_NOTEMPTY_ATSTART, // An empty string at the start of the subject is not a valid match
37+
NoJIT = PCRE2_NO_JIT, // Do not use JIT matching
38+
NoUTFCheck =
39+
PCRE2_NO_UTF_CHECK, // Do not check the subject for UTF validity(only relevant if compile_options::UTF was set at compile time)
40+
PartialHard = PCRE2_PARTIAL_HARD, // Return match_error_codes::Partial for a partial match even if there is a full match
41+
PartialSoft = PCRE2_PARTIAL_SOFT // Return match_error_codes::Partial for a partial match if no full matches are found
42+
};
43+
44+
using match_options = mstd::flags<match_options_bits>;
45+
46+
static _PCRE2CPP_CONSTEXPR17 match_options operator|(const match_options_bits opt0,
47+
const match_options_bits opt1) noexcept {
48+
return mstd::operator|(opt0, opt1);
49+
}
50+
} // namespace pcre2cpp
51+
#endif
52+
#endif

0 commit comments

Comments
 (0)