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};
// wher we can fins an encoding
// where we can fins an encoding
typedef struct enc_map {
const char *s;
encoding_t e;
@ -124,43 +124,45 @@ static enc_map_t ematches[] = {
#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) {
encoding_t rc;
int i = 0, j;
char *enc;
int i = 0;
while (encvs[i]) {
char *v = getenv(encvs[i]);
if (v) {
enc = strrchr(v, '.');
/* that's how it is supposed to be, except in OSX */
if (!enc)
enc = v;
else
enc++;
// now that we have one name, try to match it
j = 0;
while (ematches[j].s) {
if (!strcmp(ematches[j].s, enc))
return ematches[j].e;
int j = 0;
size_t sz = strlen(v);
const char *coding;
while ((coding = ematches[j].s) != NULL) {
size_t sz2 = strlen(coding);
if (sz2 > sz) {
j++;
continue;
}
if (!strcmp(coding+(sz-sz2), v) ) {
return enc_os_default(ematches[j].e);
}
j++;
}
}
i++;
}
// by default, return UTF-8
// 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;
return enc_os_default(ENC_ISO_ASCII);
}
encoding_t Yap_DefaultEncoding(void) {