ok, even if the locale is C, unicode is most often supported.

This commit is contained in:
Vítor Santos Costa 2016-03-03 23:19:19 +00:00
parent 5f9752baff
commit d3796aba5a

View File

@ -101,7 +101,7 @@ Term Yap_StringToNumberTerm(char *s, encoding_t *encp) {
const char *encvs[] = {"LANG", "LC_ALL", "LC_CTYPE", NULL}; const char *encvs[] = {"LANG", "LC_ALL", "LC_CTYPE", NULL};
// wher we can fins an encoding // where we can fins an encoding
typedef struct enc_map { typedef struct enc_map {
const char *s; const char *s;
encoding_t e; encoding_t e;
@ -117,50 +117,52 @@ static enc_map_t ematches[] = {
{"Windows-1252", ENC_ISO_LATIN1}, // almost, but not quite {"Windows-1252", ENC_ISO_LATIN1}, // almost, but not quite
{"CP-1252", ENC_ISO_LATIN1}, {"CP-1252", ENC_ISO_LATIN1},
{"C", ENC_ISO_ASCII}, {"C", ENC_ISO_ASCII},
#ifdef _WIN32 #ifdef _WIN32
{NULL, ENC_UTF16_LE} {NULL, ENC_UTF16_LE}
#else #else
{NULL, ENC_ISO_UTF8} {NULL, ENC_ISO_UTF8}
#endif #endif
}; };
static encoding_t enc_os_default( encoding_t rc)\
{
// by default, return UTF-8
// except in _WIN32
// note that we match the C locale to UTF8/16, as all Unix maachines will work on UNICODE.
if (rc == ENC_ISO_ASCII) {
#ifdef _WIN32
return = ENC_UTF16_BE;
#else
return ENC_ISO_UTF8;
#endif
}
return rc;
}
static encoding_t DefaultEncoding(void) { static encoding_t DefaultEncoding(void) {
encoding_t rc; int i = 0;
int i = 0, j;
char *enc;
while (encvs[i]) { while (encvs[i]) {
char *v = getenv(encvs[i]); char *v = getenv(encvs[i]);
if (v) { if (v) {
enc = strrchr(v, '.'); int j = 0;
/* that's how it is supposed to be, except in OSX */ size_t sz = strlen(v);
if (!enc) const char *coding;
enc = v; while ((coding = ematches[j].s) != NULL) {
else size_t sz2 = strlen(coding);
enc++; if (sz2 > sz) {
// now that we have one name, try to match it j++;
j = 0; continue;
while (ematches[j].s) { }
if (!strcmp(ematches[j].s, enc)) if (!strcmp(coding+(sz-sz2), v) ) {
return ematches[j].e; return enc_os_default(ematches[j].e);
}
j++; j++;
} }
} }
i++; i++;
} }
// by default, return UTF-8 return enc_os_default(ENC_ISO_ASCII);
// except in _WIN32
#ifdef _WIN32
rc = ENC_UTF16_BE;
#else
rc = ENC_ISO_UTF8;
#endif
{
int j = 0;
while (rc != ematches[j].e)
j++;
// Yap_Warning("YAP will use default encoding %s", ematches[j].s);
}
return rc;
} }
encoding_t Yap_DefaultEncoding(void) { encoding_t Yap_DefaultEncoding(void) {
@ -347,7 +349,7 @@ static Int tolower2(USES_REGS1) {
} }
static Int static Int
p_change_type_of_char(USES_REGS1) { /* change_type_of_char(+char,+type) */ p_change_type_of_char(USES_REGS1) { /* change_type_of_char(+char,+type) */
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
Term t2 = Deref(ARG2); Term t2 = Deref(ARG2);
if (!IsVarTerm(t1) && !IsIntegerTerm(t1)) if (!IsVarTerm(t1) && !IsIntegerTerm(t1))