INCLUDE_DIRECTORIES(${ubus_include_dir})
ADD_EXECUTABLE(nginx-ssl-util nginx-util.cpp)
-TARGET_LINK_LIBRARIES(nginx-ssl-util ${uci} ${ubox} ${ubus} pthread ssl crypto pcre)
+TARGET_LINK_LIBRARIES(nginx-ssl-util ${uci} ${ubox} ${ubus} pthread ssl crypto pcre2-8)
INSTALL(TARGETS nginx-ssl-util RUNTIME DESTINATION bin)
ADD_EXECUTABLE(nginx-ssl-util-nopcre nginx-util.cpp)
ADD_EXECUTABLE(nginx-ssl-util-noubus nginx-util.cpp)
TARGET_COMPILE_DEFINITIONS(nginx-ssl-util-noubus PUBLIC -DNO_UBUS)
-TARGET_LINK_LIBRARIES(nginx-ssl-util-noubus ${uci} ${ubox} pthread ssl crypto pcre)
+TARGET_LINK_LIBRARIES(nginx-ssl-util-noubus ${uci} ${ubox} pthread ssl crypto pcre2-8)
INSTALL(TARGETS nginx-ssl-util-noubus RUNTIME DESTINATION bin)
ADD_EXECUTABLE(nginx-ssl-util-nopcre-noubus nginx-util.cpp)
#ifndef __REGEXP_PCRE_HPP
#define __REGEXP_PCRE_HPP
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+
+#include <pcre2.h>
#include <array>
#include <stdexcept>
#include <string>
private:
int errcode = 0;
- const char* errptr = nullptr;
-
- int erroffset = 0;
+ PCRE2_SIZE erroffset = 0;
- pcre* const re = nullptr;
+ pcre2_code* const re = nullptr;
static const std::array<regex_constants::error_type, 86> errcode_pcre2regex;
explicit regex(const std::string& str) : regex(str.c_str()) {}
explicit regex(const char* const str)
- : re{pcre_compile2(str, 0, &errcode, &errptr, &erroffset, nullptr)}
+ : re{pcre2_compile((PCRE2_SPTR)str, PCRE2_ZERO_TERMINATED, 0, &errcode, &erroffset, nullptr)}
{
if (re == nullptr) {
- std::string what = std::string("regex error: ") + errptr + '\n';
+ std::vector<PCRE2_UCHAR> buffer(256);
+ int errlen;
+
+ errlen = pcre2_get_error_message(errcode, buffer.data(), buffer.size());
+ if (errlen < 0)
+ throw regex_error(errcode_pcre2regex.at(errlen));
+
+ std::string what = std::string("regex error: ") +
+ std::string(buffer.data(), buffer.data() + errlen) + '\n';
what += " '" + std::string{str} + "'\n";
what += " " + std::string(erroffset, ' ') + '^';
~regex()
{
if (re != nullptr) {
- pcre_free(re);
+ pcre2_code_free(re);
}
}
- inline auto operator()() const -> const pcre*
+ inline auto operator()() const -> const pcre2_code*
{
return re;
}
inline auto regex_search(const std::string& subj, const regex& rgx)
{
+ pcre2_match_data *match_data;
+
if (rgx() == nullptr) {
throw std::runtime_error("regex_search error: no regex given");
}
+
+ match_data = pcre2_match_data_create_from_pattern(rgx(), NULL);
+
int n =
- pcre_exec(rgx(), nullptr, subj.c_str(), static_cast<int>(subj.length()), 0, 0, nullptr, 0);
+ pcre2_match(rgx(), (PCRE2_SPTR)subj.c_str(), static_cast<int>(subj.length()), 0, 0, match_data, nullptr);
+
+ pcre2_match_data_free(match_data);
+
return n >= 0;
}
}
int sz = 0;
- pcre_fullinfo(rgx(), nullptr, PCRE_INFO_CAPTURECOUNT, &sz);
+ pcre2_pattern_info(rgx(), PCRE2_INFO_CAPTURECOUNT, &sz);
sz = 3 * (sz + 1);
match.vec.reserve(sz);
match.begin = begin;
match.end = end;
- match.n = pcre_exec(rgx(), nullptr, subj, len, 0, 0, &match.vec[0], sz);
+ pcre2_match_data *match_data = pcre2_match_data_create(sz, NULL);
+ match.n = pcre2_match(rgx(), (PCRE2_SPTR)subj, len, 0, 0, match_data, NULL);
+ pcre2_match_data_free(match_data);
if (match.n < 0) {
return false;