Skip to content

Commit 99a07c1

Browse files
committed
rewrite log_regex_error
1 parent 2000bac commit 99a07c1

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

runtime-light/stdlib/string/regex-functions.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ class preg_replacement_parser {
267267
}
268268
};
269269

270-
template<typename... Args>
271-
void log_regex_error(int32_t regex_error, std::format_string<Args..., kphp::log::impl::wrapped_arg_t<char*>> fmt, Args&&... args) noexcept {
270+
template<size_t N>
271+
void log_regex_error(const char (&msg)[N], int32_t regex_error) noexcept {
272272
std::array<char, ERROR_BUFFER_LENGTH> buffer{};
273273
pcre2_get_error_message_8(regex_error, reinterpret_cast<PCRE2_UCHAR8*>(buffer.data()), buffer.size());
274-
kphp::log::warning(fmt, std::forward<Args>(args)..., buffer.data());
274+
kphp::log::warning("{}: {}", msg, buffer.data());
275275
}
276276

277277
bool compile_regex(RegexInfo& regex_info) noexcept {
@@ -429,7 +429,7 @@ bool compile_regex(RegexInfo& regex_info) noexcept {
429429
std::addressof(error_number), std::addressof(error_offset), regex_state.compile_context.get()),
430430
pcre2_code_free_8};
431431
if (!regex_code) [[unlikely]] {
432-
log_regex_error(error_number, "can't compile pcre2 regex due to error at offset {}: {}", error_offset);
432+
log_regex_error("can't compile pcre2 regex due to error: {}", error_number);
433433
return false;
434434
}
435435

@@ -659,7 +659,7 @@ bool replace_regex(RegexInfo& regex_info, uint64_t limit) noexcept {
659659
reinterpret_cast<PCRE2_UCHAR8*>(runtime_ctx.static_SB.buffer()), std::addressof(output_length));
660660

661661
if (regex_info.replace_count < 0) [[unlikely]] {
662-
log_regex_error(regex_info.replace_count, "pcre2_substitute error {}");
662+
log_regex_error("pcre2_substitute error {}", regex_info.replace_count);
663663
return false;
664664
}
665665
} else { // replace only 'limit' times
@@ -672,7 +672,7 @@ bool replace_regex(RegexInfo& regex_info, uint64_t limit) noexcept {
672672
for (; regex_info.replace_count < limit; ++regex_info.replace_count) {
673673
auto expected_opt_match_view{pcre2_matcher.next()};
674674
if (!expected_opt_match_view.has_value()) [[unlikely]] {
675-
log_regex_error(expected_opt_match_view.error(), "can't replace by pcre2 regex due to match error: {}");
675+
log_regex_error("can't replace by pcre2 regex due to match error: {}", expected_opt_match_view.error());
676676
return false;
677677
}
678678
auto opt_match_view{*expected_opt_match_view};
@@ -727,7 +727,7 @@ std::optional<array<mixed>> split_regex(RegexInfo& regex_info, int64_t limit, bo
727727
for (size_t out_parts_count{1}; limit == kphp::regex::PREG_NOLIMIT || out_parts_count < limit;) {
728728
auto expected_opt_match_view{pcre2_matcher.next()};
729729
if (!expected_opt_match_view.has_value()) [[unlikely]] {
730-
log_regex_error(expected_opt_match_view.error(), "can't split by pcre2 regex due to match error: {}");
730+
log_regex_error("can't split by pcre2 regex due to match error: {}", expected_opt_match_view.error());
731731
return std::nullopt;
732732
}
733733
auto opt_match_view{*expected_opt_match_view};
@@ -833,7 +833,7 @@ Optional<int64_t> f$preg_match(const string& pattern, const string& subject, Opt
833833
// The return from pcre2_match() is one more than the highest numbered capturing pair that has been set
834834
// (for example, 1 if there are no captures), zero if the vector of offsets is too small, or a negative error code for no match and other errors.
835835
if (ret_code < 0 && ret_code != PCRE2_ERROR_NOMATCH) [[unlikely]] {
836-
log_regex_error(ret_code, "can't match by pcre2 regex due to error: {}");
836+
log_regex_error("can't match by pcre2 regex due to error: {}", ret_code);
837837
return false;
838838
}
839839
regex_info.match_count = ret_code != PCRE2_ERROR_NOMATCH ? ret_code : 0;
@@ -901,7 +901,7 @@ Optional<int64_t> f$preg_match_all(const string& pattern, const string& subject,
901901
expected_opt_match_view = pcre2_matcher.next();
902902
}
903903
if (!expected_opt_match_view.has_value()) [[unlikely]] {
904-
log_regex_error(expected_opt_match_view.error(), "can't find all matches due to match error: {}");
904+
log_regex_error("can't find all matches due to match error: {}", expected_opt_match_view.error());
905905
return false;
906906
}
907907

0 commit comments

Comments
 (0)