summaryrefslogtreecommitdiff
path: root/stream/obj_print.c
diff options
context:
space:
mode:
Diffstat (limited to 'stream/obj_print.c')
-rw-r--r--stream/obj_print.c38
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);