summaryrefslogtreecommitdiff
path: root/src/pcre2_printint.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pcre2_printint.c')
-rw-r--r--src/pcre2_printint.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/pcre2_printint.c b/src/pcre2_printint.c
index 2cd01ab..40a633c 100644
--- a/src/pcre2_printint.c
+++ b/src/pcre2_printint.c
@@ -7,7 +7,7 @@ and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
Original API code Copyright (c) 1997-2012 University of Cambridge
- New API code Copyright (c) 2014 University of Cambridge
+ New API code Copyright (c) 2016 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -58,12 +58,13 @@ static const char *OP_names[] = { OP_NAME_LIST };
/* The functions and tables herein must all have mode-dependent names. */
-#define OP_lengths PCRE2_SUFFIX(OP_lengths_)
-#define get_ucpname PCRE2_SUFFIX(get_ucpname_)
-#define pcre2_printint PCRE2_SUFFIX(pcre2_printint_)
-#define print_char PCRE2_SUFFIX(print_char_)
-#define print_custring PCRE2_SUFFIX(print_custring_)
-#define print_prop PCRE2_SUFFIX(print_prop_)
+#define OP_lengths PCRE2_SUFFIX(OP_lengths_)
+#define get_ucpname PCRE2_SUFFIX(get_ucpname_)
+#define pcre2_printint PCRE2_SUFFIX(pcre2_printint_)
+#define print_char PCRE2_SUFFIX(print_char_)
+#define print_custring PCRE2_SUFFIX(print_custring_)
+#define print_custring_bylen PCRE2_SUFFIX(print_custring_bylen_)
+#define print_prop PCRE2_SUFFIX(print_prop_)
/* Table of sizes for the fixed-length opcodes. It's defined in a macro so that
the definition is next to the definition of the opcodes in pcre2_internal.h.
@@ -188,12 +189,14 @@ return 0;
* Print string as a list of code units *
*************************************************/
-/* This takes no account of UTF as it always prints each individual code unit.
-The string is zero-terminated.
+/* These take no account of UTF as they always print each individual code unit.
+The string is zero-terminated for print_custring(); the length is given for
+print_custring_bylen().
Arguments:
f file to write to
ptr point to the string
+ len length for print_custring_bylen()
Returns: nothing
*/
@@ -208,6 +211,16 @@ while (*ptr != '\0')
}
}
+static void
+print_custring_bylen(FILE *f, PCRE2_SPTR ptr, PCRE2_UCHAR len)
+{
+while (len-- > 0)
+ {
+ register uint32_t c = *ptr++;
+ if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x{%x}", c);
+ }
+}
+
/*************************************************
@@ -603,7 +616,7 @@ for(;;)
c = code[1 + 4*LINK_SIZE];
fprintf(f, " %s %c", OP_names[*code], c);
extra = GET(code, 1 + 2*LINK_SIZE);
- print_custring(f, code + 2 + 4*LINK_SIZE);
+ print_custring_bylen(f, code + 2 + 4*LINK_SIZE, extra - 3 - 4*LINK_SIZE);
for (i = 0; PRIV(callout_start_delims)[i] != 0; i++)
if (c == PRIV(callout_start_delims)[i])
{
@@ -791,7 +804,7 @@ for(;;)
case OP_SKIP_ARG:
case OP_THEN_ARG:
fprintf(f, " %s ", OP_names[*code]);
- print_custring(f, code + 2);
+ print_custring_bylen(f, code + 2, code[1]);
extra += code[1];
break;