summaryrefslogtreecommitdiff
path: root/libguile/print.c
diff options
context:
space:
mode:
authorMichael Gran <spk121@yahoo.com>2010-09-26 12:25:18 -0700
committerMichael Gran <spk121@yahoo.com>2010-09-26 12:25:18 -0700
commitc03ef352bcdfcc4f00a943477f4a6eaa7499f5eb (patch)
treef28a1e8eea4ddf291c3e54e02c68516b5c6e614d /libguile/print.c
parent8445eb1db513bc68b26f0363da7ea419d7994f06 (diff)
downloadguile-c03ef352bcdfcc4f00a943477f4a6eaa7499f5eb.tar.gz
Favor non-hex string escapes over hex escapes when writing strings
The characters U+0007 to U+000D have non-hex forms for their escapes when in written strings. * libguile/print.c (write_character): use non-hex escapes * test-suite/tests/reader.test (write R6RS string escapes): adjust test
Diffstat (limited to 'libguile/print.c')
-rw-r--r--libguile/print.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/libguile/print.c b/libguile/print.c
index bdc6c9f20..ad3e8c09a 100644
--- a/libguile/print.c
+++ b/libguile/print.c
@@ -904,9 +904,17 @@ write_character (scm_t_wchar ch, SCM port, int string_escapes_p)
/* Represent CH using the in-string escape syntax. */
static const char hex[] = "0123456789abcdef";
+ static const char escapes[7] = "abtnvfr";
char buf[9];
- if (!SCM_R6RS_ESCAPES_P)
+ if (ch >= 0x07 && ch <= 0x0D && ch != 0x0A)
+ {
+ /* Use special escapes for some C0 controls. */
+ buf[0] = '\\';
+ buf[1] = escapes[ch - 0x07];
+ scm_lfwrite (buf, 2, port);
+ }
+ else if (!SCM_R6RS_ESCAPES_P)
{
if (ch <= 0xFF)
{