1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +02:00

Special case the CPUTF-8 encoding in scm_to_stringn scm_from_stringn

This commit is contained in:
Michael Gran 2023-10-08 17:55:45 -07:00
parent 1d1fde4ba1
commit dee2ac91df

View file

@ -1523,6 +1523,12 @@ scm_from_stringn (const char *str, size_t len, const char *encoding,
if (c_strcasecmp (encoding, "ISO-8859-1") == 0 || len == 0)
return scm_from_latin1_stringn (str, len);
#ifdef _WIN32
// This is a workaround for code pages unhandled by gnulib's
// locale_charset().
else if (c_strcasecmp (encoding, "CPUTF-8") == 0)
return scm_from_stringn (str, len, "UTF-8", handler);
#endif
else if (c_strcasecmp (encoding, "UTF-8") == 0
&& handler == SCM_FAILED_CONVERSION_ERROR)
return scm_from_utf8_stringn (str, len);
@ -2200,6 +2206,13 @@ scm_to_stringn (SCM str, size_t *lenp, const char *encoding,
if (encoding == NULL)
encoding = "ISO-8859-1";
#ifdef _WIN32
// This is a workaround for code pages unhandled by gnulib's
// locale_charset().
if (c_strcasecmp (encoding, "CPUTF-8") == 0)
return scm_to_stringn (str, lenp, "UTF-8", handler);
#endif
if (c_strcasecmp (encoding, "UTF-8") == 0)
/* This is the most common case--e.g., when calling libc bindings
while using a UTF-8 locale. */