Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/pcre2_printint.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,38 +463,35 @@ static void
print_class(FILE *f, PCRE2_SPTR code, const uint8_t *char_lists_end, BOOL utf,
const char *before, const char *after)
{
BOOL printmap, invertmap;
BOOL printmap, negated;
PCRE2_SPTR ccode;
int i;

fprintf(f, "%s[", before);

/* Negative XCLASS has an inverted map whereas the original opcodes have
already done the inversion. */
invertmap = FALSE;
/* Negative XCLASS and NCLASS both have a bitmap indicating which characters
are accepted. For clarity we print this inverted and prefixed by "^". */
if (*code == OP_XCLASS)
{
ccode = code + LINK_SIZE + 1;
printmap = (*ccode & XCL_MAP) != 0;
if ((*ccode & XCL_NOT) != 0)
{
invertmap = TRUE;
fprintf(f, "^");
}
negated = (*ccode & XCL_NOT) != 0;
ccode++;
}
else /* CLASS or NCLASS */
{
printmap = TRUE;
negated = *code == OP_NCLASS;
ccode = code + 1;
}

fprintf(f, "%s[%s", before, negated? "^" : "");

/* Print a bit map */
if (printmap)
{
BOOL first = TRUE;
uint8_t inverted_map[32];
const uint8_t *map = (const uint8_t *)ccode;
if (invertmap)
if (negated)
{
/* Using 255 ^ instead of ~ avoids clang sanitize warning. */
for (i = 0; i < 32; i++) inverted_map[i] = 255 ^ map[i];
Expand All @@ -507,13 +504,15 @@ if (printmap)
int j;
for (j = i+1; j < 256; j++)
if ((map[j/8] & (1u << (j&7))) == 0) break;
if (i == '-' || i == ']') fprintf(f, "\\");
if (i == '-' || i == '\\' || i == ']' || (first && i == '^'))
fprintf(f, "\\");
if (PRINTABLE(i)) fprintf(f, "%c", i);
else fprintf(f, "\\x%02x", i);
first = FALSE;
if (--j > i)
{
if (j != i + 1) fprintf(f, "-");
if (j == '-' || j == ']') fprintf(f, "\\");
if (j == '-' || j == '\\' || j == ']') fprintf(f, "\\");
if (PRINTABLE(j)) fprintf(f, "%c", j);
else fprintf(f, "\\x%02x", j);
}
Expand Down Expand Up @@ -580,7 +579,7 @@ if (*code == OP_XCLASS)
}

/* Indicate a non-UTF class which was created by negation */
fprintf(f, "]%s%s", (*code == OP_NCLASS)? " (neg)" : "", after);
fprintf(f, "]%s", after);
}


Expand Down Expand Up @@ -842,7 +841,7 @@ for(;;)
case OP_NOT:
fprintf(f, " %s [^", flag);
extra = print_char(f, code + 1, utf);
fprintf(f, "]");
fprintf(f, "] (not)");
break;

case OP_NOTSTARI:
Expand All @@ -868,7 +867,7 @@ for(;;)
case OP_NOTPOSQUERY:
fprintf(f, " %s [^", flag);
extra = print_char(f, code + 1, utf);
fprintf(f, "]%s", OP_names[*code]);
fprintf(f, "]%s (not)", OP_names[*code]);
break;

case OP_NOTEXACTI:
Expand All @@ -890,6 +889,7 @@ for(;;)
if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?");
else
if (*code == OP_NOTPOSUPTO || *code == OP_NOTPOSUPTOI) fprintf(f, "+");
fprintf(f, " (not)");
break;

case OP_RECURSE:
Expand Down
2 changes: 1 addition & 1 deletion src/pcre2test.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ to hold them as 32-bit code units. */
enum { PR_OK, PR_SKIP, PR_ABEND };

/* The macro PRINTABLE determines whether to print an output character as-is or
as a hex value when showing compiled patterns. is We use it in cases when the
as a hex value when showing compiled patterns. We use it in cases when the
locale has not been explicitly changed, so as to get consistent output from
systems that differ in their output from isprint() even in the "C" locale. */

Expand Down
14 changes: 14 additions & 0 deletions testdata/testinput2
Original file line number Diff line number Diff line change
Expand Up @@ -7228,4 +7228,18 @@ a)"xI

/[\E/

/[\^z]/B

/[ \^]/B

/[\\z]/B

/[0-z]/B

/[0\-z]/B

/[]z]/B

/[ \]]/B

# End of testinput2
12 changes: 6 additions & 6 deletions testdata/testoutput10
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Subject length lower bound = 1
/[^ab\xC0-\xF0]/IB,utf
------------------------------------------------------------------
Bra
[\x00-`c-\xbf\xf1-\xff] (neg)
[^ab\xc0-\xf0]
Ket
End
------------------------------------------------------------------
Expand Down Expand Up @@ -604,7 +604,7 @@ Subject length lower bound = 3
/[^\x{c4}]/IB
------------------------------------------------------------------
Bra
[^\x{c4}]
[^\x{c4}] (not)
Ket
End
------------------------------------------------------------------
Expand Down Expand Up @@ -648,7 +648,7 @@ Subject length lower bound = 1
/[^\xff]/IB,utf
------------------------------------------------------------------
Bra
[^\x{ff}]
[^\x{ff}] (not)
Ket
End
------------------------------------------------------------------
Expand Down Expand Up @@ -898,7 +898,7 @@ Subject length lower bound = 2
/[^\x{c4}]/IB,utf
------------------------------------------------------------------
Bra
[^\x{c4}]
[^\x{c4}] (not)
Ket
End
------------------------------------------------------------------
Expand Down Expand Up @@ -1159,7 +1159,7 @@ Subject length lower bound = 17
/[^ⱥ]/Bi,utf
------------------------------------------------------------------
Bra
/i [^\x{2c65}]
/i [^\x{2c65}] (not)
Ket
End
------------------------------------------------------------------
Expand Down Expand Up @@ -1559,7 +1559,7 @@ Subject length lower bound = 1
------------------------------------------------------------------
Bra
^
[\x00-`c-\xff] (neg)
[^ab]
Ket
End
------------------------------------------------------------------
Expand Down
68 changes: 34 additions & 34 deletions testdata/testoutput11-16
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/[^\x{c4}]/IB
------------------------------------------------------------------
Bra
[^\x{c4}]
[^\x{c4}] (not)
Ket
End
------------------------------------------------------------------
Expand Down Expand Up @@ -364,55 +364,55 @@ Subject length lower bound = 6
/[^\x{80}][^\x{ff}][^\x{100}][^\x{1000}][^\x{ffff}]/B
------------------------------------------------------------------
Bra
[^\x{80}]
[^\x{ff}]
[^\x{100}]
[^\x{1000}]
[^\x{ffff}]
[^\x{80}] (not)
[^\x{ff}] (not)
[^\x{100}] (not)
[^\x{1000}] (not)
[^\x{ffff}] (not)
Ket
End
------------------------------------------------------------------

/[^\x{80}][^\x{ff}][^\x{100}][^\x{1000}][^\x{ffff}]/Bi
------------------------------------------------------------------
Bra
/i [^\x{80}]
/i [^\x{ff}]
/i [^\x{100}]
/i [^\x{1000}]
/i [^\x{ffff}]
/i [^\x{80}] (not)
/i [^\x{ff}] (not)
/i [^\x{100}] (not)
/i [^\x{1000}] (not)
/i [^\x{ffff}] (not)
Ket
End
------------------------------------------------------------------

/[^\x{100}]*[^\x{1000}]+[^\x{ffff}]??[^\x{8000}]{4,}[^\x{7fff}]{2,9}?[^\x{100}]{5,6}+/B
------------------------------------------------------------------
Bra
[^\x{100}]*
[^\x{1000}]+
[^\x{ffff}]??
[^\x{8000}]{4}
[^\x{8000}]*
[^\x{7fff}]{2}
[^\x{7fff}]{0,7}?
[^\x{100}]{5}
[^\x{100}]?+
[^\x{100}]* (not)
[^\x{1000}]+ (not)
[^\x{ffff}]?? (not)
[^\x{8000}]{4} (not)
[^\x{8000}]* (not)
[^\x{7fff}]{2} (not)
[^\x{7fff}]{0,7}? (not)
[^\x{100}]{5} (not)
[^\x{100}]?+ (not)
Ket
End
------------------------------------------------------------------

/[^\x{100}]*[^\x{1000}]+[^\x{ffff}]??[^\x{8000}]{4,}[^\x{7fff}]{2,9}?[^\x{100}]{5,6}+/Bi
------------------------------------------------------------------
Bra
/i [^\x{100}]*
/i [^\x{1000}]+
/i [^\x{ffff}]??
/i [^\x{8000}]{4}
/i [^\x{8000}]*
/i [^\x{7fff}]{2}
/i [^\x{7fff}]{0,7}?
/i [^\x{100}]{5}
/i [^\x{100}]?+
/i [^\x{100}]* (not)
/i [^\x{1000}]+ (not)
/i [^\x{ffff}]?? (not)
/i [^\x{8000}]{4} (not)
/i [^\x{8000}]* (not)
/i [^\x{7fff}]{2} (not)
/i [^\x{7fff}]{0,7}? (not)
/i [^\x{100}]{5} (not)
/i [^\x{100}]?+ (not)
Ket
End
------------------------------------------------------------------
Expand Down Expand Up @@ -474,25 +474,25 @@ MK: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789AB
/[^\x00-a]{12,}[^b-\xff]*/B
------------------------------------------------------------------
Bra
[b-\xff] (neg){12,}
[\x00-a] (neg)*+
[^\x00-a]{12,}
[^b-\xff]*+
Ket
End
------------------------------------------------------------------

/[^\s]*\s* [^\W]+\W+ [^\d]*?\d0 [^\d\w]{4,6}?\w*A/B
------------------------------------------------------------------
Bra
[\x00-\x08\x0e-\x1f!-\xff] (neg)*
[^\x09-\x0d ]*
\s*

[0-9A-Z_a-z]++
\W+

[\x00-/:-\xff] (neg)*?
[^0-9]*?
\d
0
[\x00-/:-@[-^`{-\xff] (neg){4,6}?
[^0-9A-Z_a-z]{4,6}?
\w*
A
Ket
Expand Down
Loading