diff options
author | Karl Williamson <public@khwilliamson.com> | 2010-12-19 11:00:49 -0700 |
---|---|---|
committer | Karl Williamson <public@khwilliamson.com> | 2010-12-19 20:21:54 -0700 |
commit | 681f01c2a5ff0846090d78599b3d4caeb93fda26 (patch) | |
tree | 4fd5f0632dfb363f432dc734a6c9f5e9cb654b15 | |
parent | c8536afa2abc39d901062df19a839a4209513974 (diff) | |
download | perl-681f01c2a5ff0846090d78599b3d4caeb93fda26.tar.gz |
pv_escape: Add option to dump all non-ascii as hex
This patch adds an option to pv_escape() to dump all characters above ASCII
in hex. Before, you could get all chars as hex or the Latin1 non-ASCII
as octal, whereas the typical values for these that people think in are
given in hex.
-rw-r--r-- | dump.c | 14 | ||||
-rw-r--r-- | perl.h | 1 |
2 files changed, 10 insertions, 5 deletions
@@ -232,10 +232,11 @@ if PERL_PV_ESCAPE_UNI_DETECT is set then the input string is scanned using C<is_utf8_string()> to determine if it is Unicode. If PERL_PV_ESCAPE_ALL is set then all input chars will be output -using C<\x01F1> style escapes, otherwise only chars above 255 will be -escaped using this style, other non printable chars will use octal or -common escaped patterns like C<\n>. If PERL_PV_ESCAPE_NOBACKSLASH -then all chars below 255 will be treated as printable and +using C<\x01F1> style escapes, otherwise if PERL_PV_ESCAPE_NONASCII is set, only +chars above 127 will be escaped using this style; otherwise, only chars above +255 will be so escaped; other non printable chars will use octal or +common escaped patterns like C<\n>. Otherwise, if PERL_PV_ESCAPE_NOBACKSLASH +then all chars below 255 will be treated as printable and will be output as literals. If PERL_PV_ESCAPE_FIRSTCHAR is set then only the first char of the @@ -284,7 +285,10 @@ Perl_pv_escape( pTHX_ SV *dsv, char const * const str, const UV u= (isuni) ? utf8_to_uvchr((U8*)pv, &readsize) : (U8)*pv; const U8 c = (U8)u & 0xFF; - if ( ( u > 255 ) || (flags & PERL_PV_ESCAPE_ALL)) { + if ( ( u > 255 ) + || (flags & PERL_PV_ESCAPE_ALL) + || (( u > 127 ) && (flags & PERL_PV_ESCAPE_NONASCII))) + { if (flags & PERL_PV_ESCAPE_FIRSTCHAR) chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE, "%"UVxf, u); @@ -6159,6 +6159,7 @@ extern void moncontrol(int); #define PERL_PV_ESCAPE_UNI 0x0100 #define PERL_PV_ESCAPE_UNI_DETECT 0x0200 +#define PERL_PV_ESCAPE_NONASCII 0x0400 #define PERL_PV_ESCAPE_ALL 0x1000 #define PERL_PV_ESCAPE_NOBACKSLASH 0x2000 |