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;
@ -124,43 +124,45 @@ static enc_map_t ematches[] = {
#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) {