@@ -469,8 +469,8 @@ int i;
469469
470470fprintf (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 "^" . */
474474invertmap = FALSE;
475475if (* code == OP_XCLASS )
476476 {
@@ -486,12 +486,18 @@ if (*code == OP_XCLASS)
486486else /* 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
492497/* Print a bit map */
493498if (printmap )
494499 {
500+ BOOL first = TRUE;
495501 uint8_t inverted_map [32 ];
496502 const uint8_t * map = (const uint8_t * )ccode ;
497503 if (invertmap )
@@ -507,13 +513,15 @@ if (printmap)
507513 int j ;
508514 for (j = i + 1 ; j < 256 ; j ++ )
509515 if ((map [j /8 ] & (1u << (j & 7 ))) == 0 ) break ;
510- if (i == '-' || i == ']' ) fprintf (f , "\\" );
516+ if (i == '-' || i == '\\' || i == ']' || (first && i == '^' ))
517+ fprintf (f , "\\" );
511518 if (PRINTABLE (i )) fprintf (f , "%c" , i );
512519 else fprintf (f , "\\x%02x" , i );
520+ first = FALSE;
513521 if (-- j > i )
514522 {
515523 if (j != i + 1 ) fprintf (f , "-" );
516- if (j == '-' || j == ']' ) fprintf (f , "\\" );
524+ if (j == '-' || i == '\\' || i == ']' ) fprintf (f , "\\" );
517525 if (PRINTABLE (j )) fprintf (f , "%c" , j );
518526 else fprintf (f , "\\x%02x" , j );
519527 }
@@ -580,7 +588,7 @@ if (*code == OP_XCLASS)
580588 }
581589
582590/* Indicate a non-UTF class which was created by negation */
583- fprintf (f , "]%s%s" , ( * code == OP_NCLASS )? " (neg)" : " " , after );
591+ fprintf (f , "]%s" , after );
584592}
585593
586594
0 commit comments