Commit 645789a2 by Geoff Simmons

Add the info_bool() method.

parent 62df17f1
Pipeline #265 skipped
......@@ -94,6 +94,15 @@ regex.sub
STRING regex.sub(PRIV_CALL, PRIV_TASK, STRING subject, STRING replacement, INT len=0, BOOL anchored=0, INT match_limit=0, INT offset_limit=0, BOOL notbol=0, BOOL noteol=0, BOOL notempty=0, BOOL notempty_atstart=0, BOOL no_jit=0, BOOL no_utf_check=0, INT recursion_limit=0, BOOL suball=0, BOOL sub_extended=0, BOOL unknown_unset=0, BOOL unset_empty=0)
.. _func_regex.info_bool:
regex.info_bool
---------------
::
BOOL regex.info_bool(ENUM {ALLOW_EMPTY_CLASS,ANCHORED,ALT_BSUX,ALT_CIRCUMFLEX,ALT_VERBNAMES,CASELESS,DOLLAR_ENDONLY,DOTALL,DUPNAMES,EXTENDED,FIRSTLINE,MATCH_UNSET_BACKREF,MULTILINE,NEVER_BACKSLASH_C,NEVER_UCP,NEVER_UTF,NO_AUTO_CAPTURE,NO_AUTO_POSSESS,NO_DOTSTAR_ANCHOR,NO_START_OPTIMIZE,NO_UTF_CHECK,UCP,UNGREEDY,USE_OFFSET_LIMIT,UTF,HAS_FIRSTCODEUNIT,MATCH_ATSTART,HAS_LASTCODEUNIT,HAS_BACKSLASHC,HAS_CRORLF,JCHANGED,MATCH_EMPTY}, BOOL compiled=1)
.. _func_regex.info_int:
regex.info_int
......
......@@ -29,6 +29,150 @@
#include "vcc_if.h"
VCL_BOOL
vmod_regex_info_bool(VRT_CTX, struct vmod_pcre2_regex *regex, VCL_ENUM bools,
VCL_BOOL compiled)
{
uint32_t what, where, option, opts = PCRE2_INFO_ALLOPTIONS, codetype;
int ret;
(void) ctx;
CHECK_OBJ_NOTNULL(regex, VMOD_PCRE2_REGEX_MAGIC);
if (!compiled)
opts = PCRE2_INFO_ARGOPTIONS;
if (strcmp(bools, "ALLOW_EMPTY_CLASS") == 0) {
what = opts;
option = PCRE2_ALLOW_EMPTY_CLASS;
}
else if (strcmp(bools, "ANCHORED") == 0) {
what = opts;
option = PCRE2_ANCHORED;
}
else if (strcmp(bools, "ALT_BSUX") == 0) {
what = opts;
option = PCRE2_ANCHORED;
}
else if (strcmp(bools, "ALT_CIRCUMFLEX") == 0) {
what = opts;
option = PCRE2_ALT_CIRCUMFLEX;
}
else if (strcmp(bools, "ALT_VERBNAMES") == 0) {
what = opts;
option = PCRE2_ALT_VERBNAMES;
}
else if (strcmp(bools, "CASELESS") == 0) {
what = opts;
option = PCRE2_CASELESS;
}
else if (strcmp(bools, "DOLLAR_ENDONLY") == 0) {
what = opts;
option = PCRE2_DOLLAR_ENDONLY;
}
else if (strcmp(bools, "DOTALL") == 0) {
what = opts;
option = PCRE2_DOTALL;
}
else if (strcmp(bools, "DUPNAMES") == 0) {
what = opts;
option = PCRE2_DUPNAMES;
}
else if (strcmp(bools, "EXTENDED") == 0) {
what = opts;
option = PCRE2_EXTENDED;
}
else if (strcmp(bools, "FIRSTLINE") == 0) {
what = opts;
option = PCRE2_FIRSTLINE;
}
else if (strcmp(bools, "MATCH_UNSET_BACKREF") == 0) {
what = opts;
option = PCRE2_MATCH_UNSET_BACKREF;
}
else if (strcmp(bools, "MULTILINE") == 0) {
what = opts;
option = PCRE2_MULTILINE;
}
else if (strcmp(bools, "NEVER_BACKSLASH_C") == 0) {
what = opts;
option = PCRE2_NEVER_BACKSLASH_C;
}
else if (strcmp(bools, "NEVER_UCP") == 0) {
what = opts;
option = PCRE2_NEVER_UCP;
}
else if (strcmp(bools, "NEVER_UTF") == 0) {
what = opts;
option = PCRE2_NEVER_UTF;
}
else if (strcmp(bools, "NO_AUTO_CAPTURE") == 0) {
what = opts;
option = PCRE2_NO_AUTO_CAPTURE;
}
else if (strcmp(bools, "NO_AUTO_POSSESS") == 0) {
what = opts;
option = PCRE2_NO_AUTO_POSSESS;
}
else if (strcmp(bools, "NO_DOTSTAR_ANCHOR") == 0) {
what = opts;
option = PCRE2_NO_DOTSTAR_ANCHOR;
}
else if (strcmp(bools, "NO_START_OPTIMIZE") == 0) {
what = opts;
option = PCRE2_NO_START_OPTIMIZE;
}
else if (strcmp(bools, "NO_UTF_CHECK") == 0) {
what = opts;
option = PCRE2_NO_UTF_CHECK;
}
else if (strcmp(bools, "UCP") == 0) {
what = opts;
option = PCRE2_UCP;
}
else if (strcmp(bools, "UNGREEDY") == 0) {
what = opts;
option = PCRE2_UNGREEDY;
}
else if (strcmp(bools, "USE_OFFSET_LIMIT") == 0) {
what = opts;
option = PCRE2_USE_OFFSET_LIMIT;
}
else if (strcmp(bools, "UTF") == 0) {
what = opts;
option = PCRE2_UTF;
}
else if (strcmp(bools, "HAS_FIRSTCODEUNIT") == 0) {
what = PCRE2_INFO_FIRSTCODETYPE;
codetype = 1;
}
else if (strcmp(bools, "MATCH_ATSTART") == 0) {
what = PCRE2_INFO_FIRSTCODETYPE;
codetype = 2;
}
else if (strcmp(bools, "HAS_LASTCODEUNIT") == 0)
what = PCRE2_INFO_LASTCODETYPE;
else if (strcmp(bools, "HAS_BACKSLASHC") == 0)
what = PCRE2_INFO_HASBACKSLASHC;
else if (strcmp(bools, "HAS_CRORLF") == 0)
what = PCRE2_INFO_HASCRORLF;
else if (strcmp(bools, "JCHANGED") == 0)
what = PCRE2_INFO_JCHANGED;
else if (strcmp(bools, "MATCH_EMPTY") == 0)
what = PCRE2_INFO_MATCHEMPTY;
else
WRONG("illegal enum in info_int");
ret = pcre2_pattern_info(regex->code, what, &where);
AZ(ret);
if (what == opts)
return (where & option);
if (what == PCRE2_INFO_FIRSTCODETYPE)
return where == codetype;
return where;
}
VCL_INT
vmod_regex_info_int(VRT_CTX, struct vmod_pcre2_regex *regex, VCL_ENUM ints)
{
......
......@@ -38,6 +38,7 @@ varnish v1 -vcl {
= pcre2.match("\o{170000}", "飥", utf=true);
set resp.http.f6
= pcre2.match("[膧-膭]", "膫", utf=true);
set resp.http.info = r1.info_bool(UTF);
}
} -start
......@@ -51,6 +52,7 @@ client c1 {
expect resp.http.f4 == "true"
expect resp.http.f5 == "true"
expect resp.http.f6 == "true"
expect resp.http.info == "true"
} -run
varnish v1 -errvcl {vmod pcre2 error: Cannot compile '\x{110000}' in r constructor: character code point value in \x{} or \o{} is too large at offset 9} {
......
......@@ -51,6 +51,18 @@ $Method STRING .sub(PRIV_CALL, PRIV_TASK, STRING subject, STRING replacement,
BOOL sub_extended=0, BOOL unknown_unset=0,
BOOL unset_empty=0)
$Method BOOL .info_bool(ENUM {ALLOW_EMPTY_CLASS, ANCHORED, ALT_BSUX,
ALT_CIRCUMFLEX, ALT_VERBNAMES, CASELESS,
DOLLAR_ENDONLY, DOTALL, DUPNAMES, EXTENDED,
FIRSTLINE, MATCH_UNSET_BACKREF, MULTILINE,
NEVER_BACKSLASH_C, NEVER_UCP, NEVER_UTF,
NO_AUTO_CAPTURE, NO_AUTO_POSSESS,
NO_DOTSTAR_ANCHOR, NO_START_OPTIMIZE,
NO_UTF_CHECK, UCP, UNGREEDY, USE_OFFSET_LIMIT,
UTF, HAS_FIRSTCODEUNIT, MATCH_ATSTART,
HAS_LASTCODEUNIT, HAS_BACKSLASHC, HAS_CRORLF,
JCHANGED, MATCH_EMPTY}, BOOL compiled=1)
$Method INT .info_int(ENUM {BACKREFMAX, CAPTURECOUNT, JITSIZE, MATCHLIMIT,
MAXLOOKBEHIND, MINLENGTH, RECURSIONLIMIT, SIZE})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment