summaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2017-08-10 14:33:40 -0600
committerKarl Williamson <khw@cpan.org>2017-11-08 20:21:44 -0700
commit63ab03b3966fa7dcc24a137305becdb56bbf4e5a (patch)
tree5b9e408bc4a086edd7513da100415e28c73fce2d /utf8.c
parent604d7733597968dd3d3b15a0c50861ee7ade3f96 (diff)
downloadperl-63ab03b3966fa7dcc24a137305becdb56bbf4e5a.tar.gz
_byte_dump_string(): Don't output leading space
This changes this function to not put an initial space character in the returned string.
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/utf8.c b/utf8.c
index c6d08b6635..6107348523 100644
--- a/utf8.c
+++ b/utf8.c
@@ -952,10 +952,10 @@ Perl__is_utf8_char_helper(const U8 * const s, const U8 * e, const U32 flags)
}
char *
-Perl__byte_dump_string(pTHX_ const U8 * s, const STRLEN len, const bool format)
+Perl__byte_dump_string(pTHX_ const U8 * const start, const STRLEN len, const bool format)
{
/* Returns a mortalized C string that is a displayable copy of the 'len'
- * bytes starting at 's'. 'format' gives how to display each byte.
+ * bytes starting at 'start'. 'format' gives how to display each byte.
* Currently, there are only two formats, so it is currently a bool:
* 0 \xab
* 1 ab (that is a space between two hex digit bytes)
@@ -963,7 +963,8 @@ Perl__byte_dump_string(pTHX_ const U8 * s, const STRLEN len, const bool format)
const STRLEN output_len = 4 * len + 1; /* 4 bytes per each input, plus a
trailing NUL */
- const U8 * const e = s + len;
+ const U8 * s = start;
+ const U8 * const e = start + len;
char * output;
char * d;
@@ -973,12 +974,14 @@ Perl__byte_dump_string(pTHX_ const U8 * s, const STRLEN len, const bool format)
SAVEFREEPV(output);
d = output;
- for (; s < e; s++) {
+ for (s = start; s < e; s++) {
const unsigned high_nibble = (*s & 0xF0) >> 4;
const unsigned low_nibble = (*s & 0x0F);
if (format) {
- *d++ = ' ';
+ if (s > start) {
+ *d++ = ' ';
+ }
}
else {
*d++ = '\\';