summaryrefslogtreecommitdiff
path: root/libguile/chars.c
diff options
context:
space:
mode:
authorMichael Gran <spk121@yahoo.com>2010-01-10 15:08:19 -0800
committerMichael Gran <spk121@yahoo.com>2010-01-10 15:16:55 -0800
commit15b6a6b284f00fa790ef003a9df8c8ae5a4d7d6a (patch)
treeae8ddbfbd9b909a36a3821b963167ca95752a928 /libguile/chars.c
parentf39ede00675f0d7dcdb864e91653c4dacb98e694 (diff)
downloadguile-15b6a6b284f00fa790ef003a9df8c8ae5a4d7d6a.tar.gz
Add R6RS character names
R6RS adds new names for some of the control characters. * libguile/chars.c (scm_r6rs_charnames, scm_r6rs_charnums) (SCM_N_R6RS_CHARNAMES): new character name constants (scm_alt_charnames, scm_alt_charnums): modified to remove duplicates (scm_i_charname, scm_i_charname_to_char): use new constants * test-suite/tests/chars.test (R5RS character names, R6RS character names): new tests * doc/ref/api-data.texi (Characters): updated
Diffstat (limited to 'libguile/chars.c')
-rw-r--r--libguile/chars.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/libguile/chars.c b/libguile/chars.c
index d2749f41f..fcc43f36a 100644
--- a/libguile/chars.c
+++ b/libguile/chars.c
@@ -536,11 +536,24 @@ static const char *const scm_r5rs_charnames[] = {
};
static const scm_t_uint32 const scm_r5rs_charnums[] = {
- 0x20, 0x0A
+ 0x20, 0x0a
};
#define SCM_N_R5RS_CHARNAMES (sizeof (scm_r5rs_charnames) / sizeof (char *))
+static const char *const scm_r6rs_charnames[] = {
+ "nul", "alarm", "backspace", "tab", "linefeed", "vtab", "page",
+ "return", "esc", "delete"
+ /* 'space' and 'newline' are already included from the R5RS list. */
+};
+
+static const scm_t_uint32 const scm_r6rs_charnums[] = {
+ 0x00, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
+ 0x0d, 0x1b, 0x7f
+};
+
+#define SCM_N_R6RS_CHARNAMES (sizeof (scm_r6rs_charnames) / sizeof (char *))
+
/* The abbreviated names for control characters. */
static const char *const scm_C0_control_charnames[] = {
/* C0 controls */
@@ -562,11 +575,11 @@ static const scm_t_uint32 const scm_C0_control_charnums[] = {
#define SCM_N_C0_CONTROL_CHARNAMES (sizeof (scm_C0_control_charnames) / sizeof (char *))
static const char *const scm_alt_charnames[] = {
- "null", "backspace", "tab", "nl", "newline", "np", "page", "return",
+ "null", "nl", "np"
};
static const scm_t_uint32 const scm_alt_charnums[] = {
- 0x00, 0x08, 0x09, 0x0a, 0x0a, 0x0c, 0x0c, 0x0d
+ 0x00, 0x0a, 0x0c
};
#define SCM_N_ALT_CHARNAMES (sizeof (scm_alt_charnames) / sizeof (char *))
@@ -583,6 +596,10 @@ scm_i_charname (SCM chr)
if (scm_r5rs_charnums[c] == i)
return scm_r5rs_charnames[c];
+ for (c = 0; c < SCM_N_R6RS_CHARNAMES; c++)
+ if (scm_r6rs_charnums[c] == i)
+ return scm_r6rs_charnames[c];
+
for (c = 0; c < SCM_N_C0_CONTROL_CHARNAMES; c++)
if (scm_C0_control_charnums[c] == i)
return scm_C0_control_charnames[c];
@@ -602,14 +619,21 @@ scm_i_charname_to_char (const char *charname, size_t charname_len)
{
size_t c;
- /* The R5RS charnames. These are supposed to be case
- insensitive. */
+ /* The R5RS charnames. These are supposed to be case insensitive. */
for (c = 0; c < SCM_N_R5RS_CHARNAMES; c++)
if ((strlen (scm_r5rs_charnames[c]) == charname_len)
&& (!strncasecmp (scm_r5rs_charnames[c], charname, charname_len)))
return SCM_MAKE_CHAR (scm_r5rs_charnums[c]);
- /* Then come the controls. These are not case sensitive. */
+ /* The R6RS charnames. R6RS says that these should be case-sensitive. They
+ are left as case-insensitive to avoid confusion. */
+ for (c = 0; c < SCM_N_R6RS_CHARNAMES; c++)
+ if ((strlen (scm_r6rs_charnames[c]) == charname_len)
+ && (!strncasecmp (scm_r6rs_charnames[c], charname, charname_len)))
+ return SCM_MAKE_CHAR (scm_r6rs_charnums[c]);
+
+ /* Then come the controls. By Guile convention, these are not case
+ sensitive. */
for (c = 0; c < SCM_N_C0_CONTROL_CHARNAMES; c++)
if ((strlen (scm_C0_control_charnames[c]) == charname_len)
&& (!strncasecmp (scm_C0_control_charnames[c], charname, charname_len)))