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:
parent
bb455e4f94
commit
95f5e303bc
2 changed files with 15 additions and 45 deletions
|
@ -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)
|
||||
@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
|
||||
interpreted in the locale character encoding of the
|
||||
@code{current-input-port}.
|
||||
interpreted in the character encoding of the current locale.
|
||||
|
||||
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)
|
||||
@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
|
||||
encoding of the @code{current-output-port}. The C string must be freed
|
||||
with @code{free} eventually, maybe by using @code{scm_dynwind_free},
|
||||
Returns a C string with the same contents as @var{str} in the character
|
||||
encoding of the current locale. The C string must be freed with
|
||||
@code{free} eventually, maybe by using @code{scm_dynwind_free},
|
||||
@xref{Dynamic Wind}.
|
||||
|
||||
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
|
||||
@code{scm_to_locale_string}.
|
||||
|
||||
If a character in @var{str} cannot be represented in the locale encoding
|
||||
of the current output port, the port conversion strategy of the current
|
||||
output port will determine the result, @xref{Ports}. If output port's
|
||||
conversion strategy is @code{error}, an error will be raised. If it is
|
||||
@code{substitute}, a replacement character, such as a question mark, will
|
||||
be inserted in its place. If it is @code{escape}, a hex escape will be
|
||||
inserted in its place.
|
||||
If a character in @var{str} cannot be represented in the character
|
||||
encoding of the current locale, the default port conversion strategy is
|
||||
used. @xref{Ports}, for more on conversion strategies.
|
||||
|
||||
If the conversion strategy is @code{error}, an error will be raised. If
|
||||
it is @code{substitute}, a replacement character, such as a question
|
||||
mark, will be inserted in its place. If it is @code{escape}, a hex
|
||||
escape will be inserted in its place.
|
||||
@end deftypefn
|
||||
|
||||
@deftypefn {C Function} size_t scm_to_locale_stringbuf (SCM str, char *buf, size_t max_len)
|
||||
|
|
|
@ -1528,25 +1528,8 @@ scm_from_locale_string (const char *str)
|
|||
SCM
|
||||
scm_from_locale_stringn (const char *str, size_t len)
|
||||
{
|
||||
const char *enc;
|
||||
scm_t_string_failed_conversion_handler hndl;
|
||||
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);
|
||||
return scm_from_stringn (str, len, locale_charset (),
|
||||
scm_i_get_conversion_strategy (SCM_BOOL_F));
|
||||
}
|
||||
|
||||
SCM
|
||||
|
@ -1771,21 +1754,8 @@ scm_to_locale_string (SCM str)
|
|||
char *
|
||||
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,
|
||||
enc,
|
||||
locale_charset (),
|
||||
scm_i_get_conversion_strategy (SCM_BOOL_F));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue