Description: Port to PCRE2.
Bug-Debian: https://bugs.debian.org/1000005
Bug: https://forums.passwordmaker.org/index.php?topic=1834.0
Author: Yavor Doganov <yavor@gnu.org>
Forwarded: https://forums.passwordmaker.org/index.php?topic=1834.0
Last-Update: 2024-01-02
---

--- a/unix.mak
+++ b/unix.mak
@@ -30,7 +30,7 @@
 CFLAGS = -O2 -Wall $(DEFINES)
 CXXFLAGS = -O2 -frtti -fexceptions -Wall $(DEFINES)
 INCPATH = -I.
-LIBS = -lmhash -lpcre -lpcrecpp
+LIBS = -lmhash -lpcre2-8
 
 ifeq ($(USE_MAC), 1)
 	CFLAGS := $(CFLAGS) -m32
--- a/urlsearch.cpp
+++ b/urlsearch.cpp
@@ -24,7 +24,8 @@
 #include <string>
 #include <iostream>
 #include <sstream>
-#include <pcrecpp.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
 #include "stdafx.h"
 #include "tinyxml.h"
 #include "urlsearch.h"
@@ -32,9 +33,24 @@
 using namespace std;
 
 int UrlSearch::regexCmp(const char *regexp, const char *string) {
-	pcrecpp::RE re(regexp);
+	pcre2_code *re;
+	pcre2_match_data *md;
+	PCRE2_SPTR pat, subj;
+	PCRE2_SIZE offset;
+	int rc;
 
-	if(re.FullMatch(string)) {
+	pat = reinterpret_cast<PCRE2_SPTR>(regexp);
+	subj = reinterpret_cast<PCRE2_SPTR>(string);
+	re = pcre2_compile(pat, PCRE2_ZERO_TERMINATED, 0,
+	                   &rc, &offset, nullptr);
+	if(offset != 0) {
+		return 0;
+	}
+	md = pcre2_match_data_create_from_pattern(re, nullptr);
+	rc = pcre2_match(re, subj, PCRE2_ZERO_TERMINATED, 0, 0, md, nullptr);
+	pcre2_code_free(re);
+	pcre2_match_data_free(md);
+	if(rc >= 0) {
 		return 1;
 	}
 	else {
