mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 21:49:06 +02:00
* encoding.c: include locale.h
(rb_locale_charmap): new method Encoding.locale_charmap for nl_langinfo(CODESET). * include/ruby/encoding.h (rb_locale_charmap): declared. * main.c (main): call setlocale with LC_CTYPE. * ruby.c (locale_encoding): use rb_locale_charmap. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
685cc0f7c4
commit
0530cf9ff8
5 changed files with 32 additions and 25 deletions
32
ruby.c
32
ruby.c
|
@ -138,32 +138,14 @@ usage(const char *name)
|
|||
static rb_encoding *
|
||||
locale_encoding(void)
|
||||
{
|
||||
static const char *const langs[] = {"LC_ALL", "LC_CTYPE", "LANG",};
|
||||
const char *lang, *at;
|
||||
int i, len, idx = 0;
|
||||
char buf[32];
|
||||
rb_encoding *enc;
|
||||
VALUE codeset = rb_locale_charmap(Qnil);
|
||||
char *name = StringValueCStr(codeset);
|
||||
int idx;
|
||||
|
||||
for (i = 0; i < sizeof(langs) / sizeof(langs[0]); ++i) {
|
||||
if (!(lang = getenv(langs[i]))) continue;
|
||||
if (!(lang = strchr(lang, '.'))) continue;
|
||||
at = strchr(++lang, '@');
|
||||
if ((len = (at ? at - lang : strlen(lang))) >= sizeof(buf) - 1) continue;
|
||||
MEMCPY(buf, lang, char, len);
|
||||
buf[len] = 0;
|
||||
idx = rb_enc_find_index(buf);
|
||||
if (idx < 0 && len > 3 &&
|
||||
(strncasecmp(buf, "euc", 3) == 0 ||
|
||||
strncasecmp(buf, "utf", 3) == 0) &&
|
||||
buf[3]) {
|
||||
MEMMOVE(buf + 4, buf + 3, char, len - 2);
|
||||
buf[3] = '-';
|
||||
idx = rb_enc_find_index(buf);
|
||||
}
|
||||
enc = rb_enc_from_index(idx);
|
||||
if (enc) return enc;
|
||||
}
|
||||
return rb_default_encoding();
|
||||
idx = rb_enc_find_index(name);
|
||||
if (idx < 0)
|
||||
return rb_default_encoding();
|
||||
return rb_enc_from_index(idx);
|
||||
}
|
||||
|
||||
extern VALUE rb_load_path;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue