diff options
author | Andy Wingo <wingo@pobox.com> | 2013-01-15 14:41:26 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2013-01-15 16:32:17 +0100 |
commit | 08467a7e6116de5e21e9622b79657e113ce4b072 (patch) | |
tree | cea07109be9e1f95b73a8ec7f42bb01f5721adee /libguile/strings.c | |
parent | 99d716b6f681f5d39288efffd0ee534bb9866fa9 (diff) | |
download | guile-08467a7e6116de5e21e9622b79657e113ce4b072.tar.gz |
add scm_from_port_string and friends
* doc/ref/api-data.texi (Conversion to/from C):
* libguile/strings.h:
* libguile/strings.c (scm_from_port_string, scm_from_port_stringn):
(scm_to_port_string, scm_to_port_stringn): New functions.
* guile-readline/readline.c (internal_readline):
* libguile/strports.c (scm_strport_to_string):
* libguile/read.c (scm_read_number, scm_read_mixed_case_symbol):
(scm_read_number_and_radix, scm_read_character): Use the new
functions.
Diffstat (limited to 'libguile/strings.c')
-rw-r--r-- | libguile/strings.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/libguile/strings.c b/libguile/strings.c index 1e89e63d6..3db526e92 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -1712,6 +1712,26 @@ scm_from_utf32_stringn (const scm_t_wchar *str, size_t len) return result; } +SCM +scm_from_port_string (const char *str, SCM port) +{ + return scm_from_port_stringn (str, -1, port); +} + +SCM +scm_from_port_stringn (const char *str, size_t len, SCM port) +{ + scm_t_port *pt = SCM_PTAB_ENTRY (port); + + if (pt->encoding_mode == SCM_PORT_ENCODING_MODE_LATIN1) + return scm_from_latin1_stringn (str, len); + else if (pt->encoding_mode == SCM_PORT_ENCODING_MODE_UTF8 + && pt->ilseq_handler == SCM_FAILED_CONVERSION_ERROR) + return scm_from_utf8_stringn (str, len); + else + return scm_from_stringn (str, len, pt->encoding, pt->ilseq_handler); +} + /* Create a new scheme string from the C string STR. The memory of STR may be used directly as storage for the new string. */ /* FIXME: GC-wise, the only way to use the memory area pointed to by STR @@ -2097,6 +2117,26 @@ scm_to_utf32_stringn (SCM str, size_t *lenp) } #undef FUNC_NAME +char * +scm_to_port_string (SCM str, SCM port) +{ + return scm_to_port_stringn (str, NULL, port); +} + +char * +scm_to_port_stringn (SCM str, size_t *lenp, SCM port) +{ + scm_t_port *pt = SCM_PTAB_ENTRY (port); + + if (pt->encoding_mode == SCM_PORT_ENCODING_MODE_LATIN1 + && pt->ilseq_handler == SCM_FAILED_CONVERSION_ERROR) + return scm_to_latin1_stringn (str, lenp); + else if (pt->encoding_mode == SCM_PORT_ENCODING_MODE_UTF8) + return scm_to_utf8_stringn (str, lenp); + else + return scm_to_stringn (str, lenp, pt->encoding, pt->ilseq_handler); +} + /* Return a malloc(3)-allocated buffer containing the contents of STR encoded according to ENCODING. If LENP is non-NULL, set it to the size in bytes of the returned buffer. If the conversion to ENCODING fails, apply the strategy |