1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

scm_{to,from}_locale_string use current locale, not current ports

* libguile/strings.c (scm_to_locale_stringn, scm_from_locale_stringn):
  Use the encoding of the current locale, not of the current i/o ports.
  Also use the current conversion strategy.

* doc/ref/api-data.texi (Conversion to/from C): Update docs.
This commit is contained in:
Andy Wingo 2011-03-17 18:29:08 +01:00
parent bb455e4f94
commit 95f5e303bc
2 changed files with 15 additions and 45 deletions

View file

@ -4171,8 +4171,7 @@ using @code{scm_dynwind_free} inside an appropriate dynwind context,
@deftypefn {C Function} SCM scm_from_locale_string (const char *str) @deftypefn {C Function} SCM scm_from_locale_string (const char *str)
@deftypefnx {C Function} SCM scm_from_locale_stringn (const char *str, size_t len) @deftypefnx {C Function} SCM scm_from_locale_stringn (const char *str, size_t len)
Creates a new Scheme string that has the same contents as @var{str} when Creates a new Scheme string that has the same contents as @var{str} when
interpreted in the locale character encoding of the interpreted in the character encoding of the current locale.
@code{current-input-port}.
For @code{scm_from_locale_string}, @var{str} must be null-terminated. For @code{scm_from_locale_string}, @var{str} must be null-terminated.
@ -4201,9 +4200,9 @@ can then use @var{str} directly as its internal representation.
@deftypefn {C Function} {char *} scm_to_locale_string (SCM str) @deftypefn {C Function} {char *} scm_to_locale_string (SCM str)
@deftypefnx {C Function} {char *} scm_to_locale_stringn (SCM str, size_t *lenp) @deftypefnx {C Function} {char *} scm_to_locale_stringn (SCM str, size_t *lenp)
Returns a C string with the same contents as @var{str} in the locale Returns a C string with the same contents as @var{str} in the character
encoding of the @code{current-output-port}. The C string must be freed encoding of the current locale. The C string must be freed with
with @code{free} eventually, maybe by using @code{scm_dynwind_free}, @code{free} eventually, maybe by using @code{scm_dynwind_free},
@xref{Dynamic Wind}. @xref{Dynamic Wind}.
For @code{scm_to_locale_string}, the returned string is For @code{scm_to_locale_string}, the returned string is
@ -4217,13 +4216,14 @@ returned string will not be null-terminated in this case. If
@var{lenp} is @code{NULL}, @code{scm_to_locale_stringn} behaves like @var{lenp} is @code{NULL}, @code{scm_to_locale_stringn} behaves like
@code{scm_to_locale_string}. @code{scm_to_locale_string}.
If a character in @var{str} cannot be represented in the locale encoding If a character in @var{str} cannot be represented in the character
of the current output port, the port conversion strategy of the current encoding of the current locale, the default port conversion strategy is
output port will determine the result, @xref{Ports}. If output port's used. @xref{Ports}, for more on conversion strategies.
conversion strategy is @code{error}, an error will be raised. If it is
@code{substitute}, a replacement character, such as a question mark, will If the conversion strategy is @code{error}, an error will be raised. If
be inserted in its place. If it is @code{escape}, a hex escape will be it is @code{substitute}, a replacement character, such as a question
inserted in its place. mark, will be inserted in its place. If it is @code{escape}, a hex
escape will be inserted in its place.
@end deftypefn @end deftypefn
@deftypefn {C Function} size_t scm_to_locale_stringbuf (SCM str, char *buf, size_t max_len) @deftypefn {C Function} size_t scm_to_locale_stringbuf (SCM str, char *buf, size_t max_len)

View file

@ -1528,25 +1528,8 @@ scm_from_locale_string (const char *str)
SCM SCM
scm_from_locale_stringn (const char *str, size_t len) scm_from_locale_stringn (const char *str, size_t len)
{ {
const char *enc; return scm_from_stringn (str, len, locale_charset (),
scm_t_string_failed_conversion_handler hndl; scm_i_get_conversion_strategy (SCM_BOOL_F));
SCM inport;
scm_t_port *pt;
inport = scm_current_input_port ();
if (!SCM_UNBNDP (inport) && SCM_OPINPORTP (inport))
{
pt = SCM_PTAB_ENTRY (inport);
enc = pt->encoding;
hndl = pt->ilseq_handler;
}
else
{
enc = NULL;
hndl = SCM_FAILED_CONVERSION_ERROR;
}
return scm_from_stringn (str, len, enc, hndl);
} }
SCM SCM
@ -1771,21 +1754,8 @@ scm_to_locale_string (SCM str)
char * char *
scm_to_locale_stringn (SCM str, size_t *lenp) scm_to_locale_stringn (SCM str, size_t *lenp)
{ {
SCM outport;
scm_t_port *pt;
const char *enc;
outport = scm_current_output_port ();
if (!SCM_UNBNDP (outport) && SCM_OPOUTPORTP (outport))
{
pt = SCM_PTAB_ENTRY (outport);
enc = pt->encoding;
}
else
enc = NULL;
return scm_to_stringn (str, lenp, return scm_to_stringn (str, lenp,
enc, locale_charset (),
scm_i_get_conversion_strategy (SCM_BOOL_F)); scm_i_get_conversion_strategy (SCM_BOOL_F));
} }