Merge branch 'pcre2' into upstream-master
* pcre2: Add changes entry for PCRE2 Call -pcreversion during appveyor testing Few more PCRE to PCRE2 changes PCRE2
This commit is contained in:
commit
543994c8ee
15 changed files with 151 additions and 152 deletions
|
|
@ -137,7 +137,7 @@ static const char *usage4 = (const char *) "\
|
|||
-oh <headfile> - Set name of C++ output header file for directors to <headfile>\n\
|
||||
-outcurrentdir - Set default output dir to current dir instead of input file's path\n\
|
||||
-outdir <dir> - Set language specific files output directory to <dir>\n\
|
||||
-pcreversion - Display PCRE version information\n\
|
||||
-pcreversion - Display PCRE2 version information\n\
|
||||
-small - Compile in virtual elimination and compact mode\n\
|
||||
-swiglib - Report location of SWIG library and exit\n\
|
||||
-templatereduce - Reduce all the typedefs in templates\n\
|
||||
|
|
|
|||
|
|
@ -1312,7 +1312,8 @@ void Swig_offset_string(String *s, int number) {
|
|||
|
||||
|
||||
#ifdef HAVE_PCRE
|
||||
#include <pcre.h>
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#include <pcre2.h>
|
||||
|
||||
static int split_regex_pattern_subst(String *s, String **pattern, String **subst, const char **input)
|
||||
{
|
||||
|
|
@ -1375,7 +1376,7 @@ static void copy_with_maybe_case_conversion(String *dst, const char *src, int le
|
|||
}
|
||||
}
|
||||
|
||||
String *replace_captures(int num_captures, const char *input, String *subst, int captures[], String *pattern, String *s)
|
||||
String *replace_captures(int num_captures, const char *input, String *subst, size_t captures[], String *pattern, String *s)
|
||||
{
|
||||
int convertCase = 0, convertNextOnly = 0;
|
||||
String *result = NewStringEmpty();
|
||||
|
|
@ -1397,7 +1398,7 @@ String *replace_captures(int num_captures, const char *input, String *subst, int
|
|||
} else if (isdigit((unsigned char)*p)) {
|
||||
int group = *p++ - '0';
|
||||
if (group < num_captures) {
|
||||
int l = captures[group*2], r = captures[group*2 + 1];
|
||||
int l = (int)captures[group*2], r = (int)captures[group*2 + 1];
|
||||
if (l != -1) {
|
||||
copy_with_maybe_case_conversion(result, input + l, r - l, &convertCase, convertNextOnly);
|
||||
}
|
||||
|
|
@ -1449,26 +1450,31 @@ String *Swig_string_regex(String *s) {
|
|||
const int pcre_options = 0;
|
||||
|
||||
String *res = 0;
|
||||
pcre *compiled_pat = 0;
|
||||
const char *pcre_error, *input;
|
||||
int pcre_errorpos;
|
||||
pcre2_code *compiled_pat = 0;
|
||||
const char *input;
|
||||
PCRE2_UCHAR pcre_error[256];
|
||||
int pcre_errornum;
|
||||
size_t pcre_errorpos;
|
||||
String *pattern = 0, *subst = 0;
|
||||
int captures[30];
|
||||
|
||||
size_t *captures = 0;
|
||||
pcre2_match_data *match_data = 0;
|
||||
if (split_regex_pattern_subst(s, &pattern, &subst, &input)) {
|
||||
int rc;
|
||||
|
||||
compiled_pat = pcre_compile(
|
||||
Char(pattern), pcre_options, &pcre_error, &pcre_errorpos, NULL);
|
||||
compiled_pat = pcre2_compile(
|
||||
(PCRE2_SPTR8)Char(pattern), PCRE2_ZERO_TERMINATED, pcre_options, &pcre_errornum, &pcre_errorpos, NULL);
|
||||
if (!compiled_pat) {
|
||||
pcre2_get_error_message (pcre_errornum, pcre_error, sizeof pcre_error);
|
||||
Swig_error("SWIG", Getline(s), "PCRE compilation failed: '%s' in '%s':%i.\n",
|
||||
pcre_error, Char(pattern), pcre_errorpos);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
rc = pcre_exec(compiled_pat, NULL, input, (int)strlen(input), 0, 0, captures, 30);
|
||||
match_data = pcre2_match_data_create_from_pattern (compiled_pat, NULL);
|
||||
rc = pcre2_match(compiled_pat, (PCRE2_SPTR8)input, PCRE2_ZERO_TERMINATED, 0, 0, match_data, NULL);
|
||||
captures = pcre2_get_ovector_pointer (match_data);
|
||||
if (rc >= 0) {
|
||||
res = replace_captures(rc, input, subst, captures, pattern, s);
|
||||
} else if (rc != PCRE_ERROR_NOMATCH) {
|
||||
} else if (rc != PCRE2_ERROR_NOMATCH) {
|
||||
Swig_error("SWIG", Getline(s), "PCRE execution failed: error %d while matching \"%s\" using \"%s\".\n",
|
||||
rc, Char(pattern), input);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
|
|
@ -1477,12 +1483,19 @@ String *Swig_string_regex(String *s) {
|
|||
|
||||
DohDelete(pattern);
|
||||
DohDelete(subst);
|
||||
pcre_free(compiled_pat);
|
||||
pcre2_code_free(compiled_pat);
|
||||
pcre2_match_data_free(match_data);
|
||||
return res ? res : NewStringEmpty();
|
||||
}
|
||||
|
||||
String *Swig_pcre_version(void) {
|
||||
return NewStringf("PCRE Version: %s", pcre_version());
|
||||
int len = pcre2_config(PCRE2_CONFIG_VERSION, NULL);
|
||||
char *buf = malloc(len);
|
||||
String *result;
|
||||
pcre2_config(PCRE2_CONFIG_VERSION, buf);
|
||||
result = NewStringf("PCRE2 Version: %s", buf);
|
||||
free(buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -1092,26 +1092,32 @@ static DOH *get_lattr(Node *n, List *lattr) {
|
|||
}
|
||||
|
||||
#ifdef HAVE_PCRE
|
||||
#include <pcre.h>
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#include <pcre2.h>
|
||||
|
||||
static int name_regexmatch_value(Node *n, String *pattern, String *s) {
|
||||
pcre *compiled_pat;
|
||||
const char *err;
|
||||
int errpos;
|
||||
pcre2_code *compiled_pat;
|
||||
PCRE2_UCHAR err[256];
|
||||
int errornum;
|
||||
size_t errpos;
|
||||
int rc;
|
||||
|
||||
compiled_pat = pcre_compile(Char(pattern), 0, &err, &errpos, NULL);
|
||||
compiled_pat = pcre2_compile((PCRE2_SPTR8)Char(pattern), PCRE2_ZERO_TERMINATED, 0, &errornum, &errpos, NULL);
|
||||
if (!compiled_pat) {
|
||||
pcre2_get_error_message (errornum, err, sizeof err);
|
||||
Swig_error("SWIG", Getline(n),
|
||||
"Invalid regex \"%s\": compilation failed at %d: %s\n",
|
||||
Char(pattern), errpos, err);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
rc = pcre_exec(compiled_pat, NULL, Char(s), Len(s), 0, 0, NULL, 0);
|
||||
pcre_free(compiled_pat);
|
||||
pcre2_match_data *match_data = 0;
|
||||
match_data = pcre2_match_data_create_from_pattern (compiled_pat, NULL);
|
||||
rc = pcre2_match(compiled_pat, (PCRE2_SPTR8)Char(s), PCRE2_ZERO_TERMINATED, 0, 0, match_data, 0);
|
||||
pcre2_code_free(compiled_pat);
|
||||
pcre2_match_data_free(match_data);
|
||||
|
||||
if (rc == PCRE_ERROR_NOMATCH)
|
||||
if (rc == PCRE2_ERROR_NOMATCH)
|
||||
return 0;
|
||||
|
||||
if (rc < 0 ) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue