diff options
author | Tor Andersson <tor@ghostscript.com> | 2006-09-22 21:31:27 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2006-09-22 21:31:27 +0200 |
commit | 933bc2f332e64561d9d33aa3cbfc5c63fb45a9be (patch) | |
tree | fd5f03a9b529670f0de4a917b2a5012652804dce /stream/obj_print.c | |
parent | 3f1f75a50d9e09d4a9dc027d0e303a0bdce2850e (diff) | |
download | mupdf-933bc2f332e64561d9d33aa3cbfc5c63fb45a9be.tar.xz |
hex-encode names with white-space and delimiters on output
Diffstat (limited to 'stream/obj_print.c')
-rw-r--r-- | stream/obj_print.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/stream/obj_print.c b/stream/obj_print.c index e58462b3..32072306 100644 --- a/stream/obj_print.c +++ b/stream/obj_print.c @@ -15,6 +15,17 @@ struct fmt static void fmtobj(struct fmt *fmt, fz_obj *obj); +static inline int iswhite(int ch) +{ + return + ch == '\000' || + ch == '\011' || + ch == '\012' || + ch == '\014' || + ch == '\015' || + ch == '\040'; +} + static inline int isdelim(int ch) { return ch == '(' || ch == ')' || @@ -118,6 +129,30 @@ static void fmthex(struct fmt *fmt, fz_obj *obj) fmtputc(fmt, '>'); } +static void fmtname(struct fmt *fmt, fz_obj *obj) +{ + char *s = fz_toname(obj); + int i, c; + + fmtputc(fmt, '/'); + + for (i = 0; s[i]; i++) + { + if (isdelim(s[i]) || iswhite(s[i])) + { + fmtputc(fmt, '#'); + c = (s[i] >> 4) & 0xf; + fmtputc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA); + c = s[i] & 0xf; + fmtputc(fmt, c < 0xA ? c + '0' : c + 'A' - 0xA); + } + else + { + fmtputc(fmt, s[i]); + } + } +} + static void fmtarray(struct fmt *fmt, fz_obj *obj) { int i; @@ -231,8 +266,7 @@ static void fmtobj(struct fmt *fmt, fz_obj *obj) } break; case FZ_NAME: - sprintf(buf, "/%s", fz_toname(obj)); - fmtputs(fmt, buf); + fmtname(fmt, obj); break; case FZ_ARRAY: fmtarray(fmt, obj); |