@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.
@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
@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)
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
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));
}