From 3692abf61e798c6980ab32960cf4ffc8d8779091 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 10 Oct 2014 13:49:34 -0600 Subject: [PATCH] Windows: add "CP" before code page number as locale encoding If you set the locale to something like "us_EN.1252", then "1252" was returned as the encoding, but "CP1252" is more likely to be recognized by `bytes-open-converter`. --- racket/src/racket/src/string.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/racket/src/racket/src/string.c b/racket/src/racket/src/string.c index b757ff94c9..7ba4207c7c 100644 --- a/racket/src/racket/src/string.c +++ b/racket/src/racket/src/string.c @@ -195,11 +195,27 @@ static char *nl_langinfo(int which) for (i = 0; current_locale_name[i]; i++) { if (current_locale_name[i] == '.') { if (current_locale_name[i + 1]) { - int len, j = 0; + int len, j; char *enc; i++; len = scheme_char_strlen(current_locale_name) - i; - enc = (char *)scheme_malloc_atomic(len + 1); + enc = (char *)scheme_malloc_atomic(2 + len + 1); + + /* Check whether the encoding is numberic, in which case + we add "CP" in front to make it an encoding name */ + for (j = i; current_locale_name[j]; j++) { + if (current_locale_name[j] > 127) + break; + if (!isdigit(current_locale_name[j])) + break; + } + if (!current_locale_name[j]) { + j = 2; + memcpy(enc, "CP", j); + } else { + j = 0; + } + while (current_locale_name[i]) { if (current_locale_name[i] > 127) return "UTF-8";