Skip to content

Commit 0e9a0e2

Browse files
committed
review
1 parent df39ad9 commit 0e9a0e2

6 files changed

Lines changed: 18 additions & 15 deletions

File tree

private/rdf4cpp/regex/RegexImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ namespace rdf4cpp::regex {
114114
auto s = make_code(regex, flags, 0);
115115
return {std::move(m), std::move(s), flags};
116116
}
117-
Regex::Impl::Impl(code_ptr m, code_ptr s, flag_type f)
118-
: match(std::move(m)),
119-
search(std::move(s)),
120-
flags(f) {
117+
Regex::Impl::Impl(code_ptr match, code_ptr search, flag_type flags)
118+
: match(std::move(match)),
119+
search(std::move(search)),
120+
flags(flags) {
121121
}
122122

123123
} //namespace rdf4cpp::regex

private/rdf4cpp/regex/RegexImpl.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace rdf4cpp::regex {
1010
struct Regex::Impl {
11+
private:
1112
// workaround for gcc-14 bug, erroneously warns on unsing a lambda here
1213
// see https://github.com/NVIDIA/stdexec/issues/1143
1314
template<auto f>
@@ -18,6 +19,8 @@ namespace rdf4cpp::regex {
1819
};
1920

2021
using code_ptr = std::unique_ptr<pcre2_code_8, CallFree<pcre2_code_free_8>>;
22+
23+
public:
2124
code_ptr match;
2225
code_ptr search;
2326
Regex::flag_type flags;
@@ -34,7 +37,7 @@ namespace rdf4cpp::regex {
3437
static code_ptr make_code(std::string_view regex, flag_type flags, int extra_flags);
3538
static std::string remove_whitespace(std::string_view str);
3639
static Impl make(std::string_view regex, flag_type flags);
37-
Impl(code_ptr m, code_ptr s, flag_type f);
40+
Impl(code_ptr match, code_ptr search, flag_type flags);
3841
};
3942
} //namespace rdf4cpp::regex
4043

private/rdf4cpp/regex/RegexReplacerImpl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
#include <uni_algo/conv.h>
55

66
namespace rdf4cpp::regex {
7-
std::string RegexReplacer::Impl::translate_rewrite(std::string_view const s) {
7+
static std::string translate_rewrite(std::string_view const s) {
88
std::string res{s};
99

1010
auto pos = res.find_first_of("$\\");
1111
while (pos < res.size()) {
12-
if (res[pos] == '\\') { // NOLINT(*-pro-bounds-avoid-unchecked-container-access)
13-
if (res.size() <= pos) {
14-
throw RegexError{"invalid escape sequence in replacement string"};
12+
if (res[pos] == '\\') {
13+
if (res.size() <= pos + 1) {
14+
throw RegexError{"incomplete escape sequence in replacement string"};
1515
}
16-
if (res.at(pos + 1) == '$') {
17-
res[pos] = '$'; // NOLINT(*-pro-bounds-avoid-unchecked-container-access)
16+
if (res[pos + 1] == '$') {
17+
res[pos] = '$';
1818
++pos;
19-
} else if (res.at(pos + 1) == '\\') {
19+
} else if (res[pos + 1] == '\\') {
2020
res.erase(pos, 1);
2121
} else {
2222
throw RegexError{"incomplete escape sequence in replacement string"};

private/rdf4cpp/regex/RegexReplacerImpl.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ namespace rdf4cpp::regex {
1212

1313
Impl(std::shared_ptr<Regex::Impl const> regex, std::string_view rewrite);
1414
void regex_replace(std::string &str) const;
15-
16-
private:
17-
static std::string translate_rewrite(std::string_view s);
1815
};
1916

2017
} //namespace rdf4cpp::regex

src/rdf4cpp/regex/RegexFlags.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum struct RegexFlag : uint8_t {
1212
Literal = 1 << 2,
1313
Multiline = 1 << 3,
1414
RemoveWhitespace = 1 << 4,
15+
// enables extra optimization during the parse process (currently JIT-compiling), leading to an increase in regex compile time, but faster matching & replacing
1516
Optimize = 1 << 5,
1617
};
1718

tests/util/tests_Regex.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ TEST_SUITE("regex") {
197197
CHECK(d == "b_b_x");
198198
Regex{"_(\\w)", f}.make_replacer(R"(-$0$1\$\\)").regex_replace(d);
199199
CHECK(d == "b-_bb$\\-_xx$\\");
200+
201+
CHECK_THROWS_WITH_AS(static_cast<void>(Regex{"a", f}.make_replacer("\\")), "incomplete escape sequence in replacement string", RegexError);
200202
}
201203
TEST_CASE("basic syntax") {
202204
SUBCASE("normal") {

0 commit comments

Comments
 (0)