Skip to content

Commit 0e2bf18

Browse files
committed
Use [^...] rather than '[...] (neg)' to print NCLASS
1 parent 833ab6d commit 0e2bf18

File tree

9 files changed

+62
-57
lines changed

9 files changed

+62
-57
lines changed

src/pcre2_printint.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ int i;
469469

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

472-
/* Negative XCLASS has an inverted map whereas the original opcodes have
473-
already done the inversion. */
472+
/* Negative XCLASS and NCLASS both have a bitmap indicating which characters
473+
are accepted. For clarity we print this inverted and prefixed by "^". */
474474
invertmap = FALSE;
475475
if (*code == OP_XCLASS)
476476
{
@@ -486,6 +486,11 @@ if (*code == OP_XCLASS)
486486
else /* CLASS or NCLASS */
487487
{
488488
printmap = TRUE;
489+
if (*code == OP_NCLASS)
490+
{
491+
invertmap = TRUE;
492+
fprintf(f, "^");
493+
}
489494
ccode = code + 1;
490495
}
491496

@@ -580,7 +585,7 @@ if (*code == OP_XCLASS)
580585
}
581586

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

586591

testdata/testoutput10

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ Subject length lower bound = 1
461461
/[^ab\xC0-\xF0]/IB,utf
462462
------------------------------------------------------------------
463463
Bra
464-
[\x00-`c-\xbf\xf1-\xff] (neg)
464+
[^ab\xc0-\xf0]
465465
Ket
466466
End
467467
------------------------------------------------------------------
@@ -1559,7 +1559,7 @@ Subject length lower bound = 1
15591559
------------------------------------------------------------------
15601560
Bra
15611561
^
1562-
[\x00-`c-\xff] (neg)
1562+
[^ab]
15631563
Ket
15641564
End
15651565
------------------------------------------------------------------

testdata/testoutput11-16

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,25 +474,25 @@ MK: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789AB
474474
/[^\x00-a]{12,}[^b-\xff]*/B
475475
------------------------------------------------------------------
476476
Bra
477-
[b-\xff] (neg){12,}
478-
[\x00-a] (neg)*+
477+
[^\x00-a]{12,}
478+
[^b-\xff]*+
479479
Ket
480480
End
481481
------------------------------------------------------------------
482482

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

489489
[0-9A-Z_a-z]++
490490
\W+
491491

492-
[\x00-/:-\xff] (neg)*?
492+
[^0-9]*?
493493
\d
494494
0
495-
[\x00-/:-@[-^`{-\xff] (neg){4,6}?
495+
[^0-9A-Z_a-z]{4,6}?
496496
\w*
497497
A
498498
Ket

testdata/testoutput11-32

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,25 +474,25 @@ MK: 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789AB
474474
/[^\x00-a]{12,}[^b-\xff]*/B
475475
------------------------------------------------------------------
476476
Bra
477-
[b-\xff] (neg){12,}
478-
[\x00-a] (neg)*+
477+
[^\x00-a]{12,}
478+
[^b-\xff]*+
479479
Ket
480480
End
481481
------------------------------------------------------------------
482482

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

489489
[0-9A-Z_a-z]++
490490
\W+
491491

492-
[\x00-/:-\xff] (neg)*?
492+
[^0-9]*?
493493
\d
494494
0
495-
[\x00-/:-@[-^`{-\xff] (neg){4,6}?
495+
[^0-9A-Z_a-z]{4,6}?
496496
\w*
497497
A
498498
Ket

testdata/testoutput12-16

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Subject length lower bound = 1
241241
/[^ab\xC0-\xF0]/IB,utf
242242
------------------------------------------------------------------
243243
Bra
244-
[\x00-`c-\xbf\xf1-\xff] (neg)
244+
[^ab\xc0-\xf0]
245245
Ket
246246
End
247247
------------------------------------------------------------------
@@ -1377,7 +1377,7 @@ Subject length lower bound = 2
13771377
/[\W\pL]/B
13781378
------------------------------------------------------------------
13791379
Bra
1380-
[\x00-/:-^`-\xff] (neg)
1380+
[^0-9_]
13811381
Ket
13821382
End
13831383
------------------------------------------------------------------
@@ -1394,7 +1394,7 @@ No match
13941394
/[\s[:^ascii:]]/B,ucp
13951395
------------------------------------------------------------------
13961396
Bra
1397-
[\x09-\x0d \x80-\xff] (neg)
1397+
[^\x00-\x08\x0e-\x1f!-\x7f]
13981398
Ket
13991399
End
14001400
------------------------------------------------------------------
@@ -1423,7 +1423,7 @@ Failed: error 191 at offset 0: PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES is not allowe
14231423
------------------------------------------------------------------
14241424
Bra
14251425
^
1426-
[\x00-`c-\xff] (neg)
1426+
[^ab]
14271427
Ket
14281428
End
14291429
------------------------------------------------------------------

testdata/testoutput12-32

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Subject length lower bound = 1
236236
/[^ab\xC0-\xF0]/IB,utf
237237
------------------------------------------------------------------
238238
Bra
239-
[\x00-`c-\xbf\xf1-\xff] (neg)
239+
[^ab\xc0-\xf0]
240240
Ket
241241
End
242242
------------------------------------------------------------------
@@ -1371,7 +1371,7 @@ Failed: error -28: UTF-32 error: code points greater than 0x10ffff are not defin
13711371
/[\W\pL]/B
13721372
------------------------------------------------------------------
13731373
Bra
1374-
[\x00-/:-^`-\xff] (neg)
1374+
[^0-9_]
13751375
Ket
13761376
End
13771377
------------------------------------------------------------------
@@ -1388,7 +1388,7 @@ No match
13881388
/[\s[:^ascii:]]/B,ucp
13891389
------------------------------------------------------------------
13901390
Bra
1391-
[\x09-\x0d \x80-\xff] (neg)
1391+
[^\x00-\x08\x0e-\x1f!-\x7f]
13921392
Ket
13931393
End
13941394
------------------------------------------------------------------
@@ -1420,7 +1420,7 @@ Subject length lower bound = 1
14201420
------------------------------------------------------------------
14211421
Bra
14221422
^
1423-
[\x00-`c-\xff] (neg)
1423+
[^ab]
14241424
Ket
14251425
End
14261426
------------------------------------------------------------------

testdata/testoutput2

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ Subject length lower bound = 1
17741774
------------------------------------------------------------------
17751775
Bra
17761776
^
1777-
[\x00-/:-@[-`{-\xff] (neg)
1777+
[^0-9A-Za-z]
17781778
Ket
17791779
End
17801780
------------------------------------------------------------------
@@ -1814,7 +1814,7 @@ Subject length lower bound = 1
18141814
------------------------------------------------------------------
18151815
Bra
18161816
^
1817-
[\x00-@[-`{-\xff] (neg)
1817+
[^A-Za-z]
18181818
Ket
18191819
End
18201820
------------------------------------------------------------------
@@ -1865,7 +1865,7 @@ Subject length lower bound = 1
18651865
------------------------------------------------------------------
18661866
Bra
18671867
^
1868-
[\x80-\xff] (neg)
1868+
[^\x00-\x7f]
18691869
Ket
18701870
End
18711871
------------------------------------------------------------------
@@ -1901,7 +1901,7 @@ Subject length lower bound = 1
19011901
------------------------------------------------------------------
19021902
Bra
19031903
^
1904-
[\x00-\x08\x0a-\x1f!-\xff] (neg)
1904+
[^\x09 ]
19051905
Ket
19061906
End
19071907
------------------------------------------------------------------
@@ -2082,7 +2082,7 @@ Subject length lower bound = 1
20822082
------------------------------------------------------------------
20832083
Bra
20842084
^
2085-
[ -~\x80-\xff] (neg)
2085+
[^\x00-\x1f\x7f]
20862086
Ket
20872087
End
20882088
------------------------------------------------------------------
@@ -2107,7 +2107,7 @@ Subject length lower bound = 1
21072107
------------------------------------------------------------------
21082108
Bra
21092109
^
2110-
[\x00-/12:-\xff] (neg)
2110+
[^03-9]
21112111
Ket
21122112
End
21132113
------------------------------------------------------------------
@@ -2134,7 +2134,7 @@ Subject length lower bound = 1
21342134
------------------------------------------------------------------
21352135
Bra
21362136
^
2137-
[\x00-\x08\x0a-\x1f!-\xff] (neg)
2137+
[^\x09 ]
21382138
Ket
21392139
End
21402140
------------------------------------------------------------------
@@ -2711,7 +2711,7 @@ Subject length lower bound = 1
27112711
/[\S]/IB
27122712
------------------------------------------------------------------
27132713
Bra
2714-
[\x00-\x08\x0e-\x1f!-\xff] (neg)
2714+
[^\x09-\x0d ]
27152715
Ket
27162716
End
27172717
------------------------------------------------------------------
@@ -9466,7 +9466,7 @@ Partial match: ab
94669466
Cond false
94679467
CBra 1
94689468
<
9469-
[\x00-/:-\xff] (neg)
9469+
[^0-9]
94709470
[^>]
94719471
>
94729472
[^<]
@@ -13082,11 +13082,11 @@ Subject length lower bound = 5
1308213082
[a-d]{5,12}+
1308313083
[0-9e-z]*+
1308413084
#
13085-
[\x00-`{-\xff] (neg)++
13085+
[^a-z]++
1308613086
[b-y]*+
1308713087
a
1308813088
[2-7]?+
13089-
[\x00-/:-`{-\xff] (neg)++
13089+
[^0-9a-z]++
1309013090
Ket
1309113091
End
1309213092
------------------------------------------------------------------
@@ -13325,7 +13325,7 @@ Failed: error 178 at offset 5: digits missing after \x or in \x{} or \o{} or \N{
1332513325
/[^ab]*+/B,no_auto_possess
1332613326
------------------------------------------------------------------
1332713327
Bra
13328-
[\x00-`c-\xff] (neg)*+
13328+
[^ab]*+
1332913329
Ket
1333013330
End
1333113331
------------------------------------------------------------------
@@ -15617,7 +15617,7 @@ Subject length lower bound = 0
1561715617
T?
1561815618
*MARK ;.'?`(\x{ea}p
1561915619
{!
15620-
[\x00- "-&+-:<->@-BD-xz-\xff] (neg)
15620+
[^!'-*;?Cy]
1562115621
{1;
1562215622
CBra 1
1562315623
\x08
@@ -19738,7 +19738,7 @@ No match
1973819738
------------------------------------------------------------------
1973919739
Bra
1974019740
eclass[
19741-
cls:[\x00-@B-\xff] (neg)
19741+
cls:[^A]
1974219742
cls:[B]
1974319743
op: ||
1974419744
]
@@ -19900,7 +19900,7 @@ No match
1990019900
Bra
1990119901
eclass[
1990219902
cls:[A]
19903-
cls:[\x00-\^-\xff] (neg)
19903+
cls:[^\]]
1990419904
op: ||
1990519905
]
1990619906
Ket
@@ -20018,7 +20018,7 @@ No match
2001820018
Bra
2001920019
eclass[
2002020020
cls:[\x09-\x0d 0-9AC-E]
20021-
cls:[\x00-y{-\xff] (neg)
20021+
cls:[^z]
2002220022
op: &&
2002320023
]
2002420024
Ket
@@ -20049,7 +20049,7 @@ No match
2004920049
Bra
2005020050
eclass[
2005120051
cls:[z]
20052-
cls:[\x00-\x08\x0e-\x1f!-/:-@BF-\xff] (neg)
20052+
cls:[^\x09-\x0d 0-9AC-E]
2005320053
op: ||
2005420054
]
2005520055
Ket
@@ -20249,7 +20249,7 @@ No match
2024920249
Bra
2025020250
eclass[
2025120251
cls:[a]
20252-
cls:[\x00-ac-\xff] (neg)
20252+
cls:[^b]
2025320253
op: ||
2025420254
op: ^
2025520255
]

0 commit comments

Comments
 (0)