* 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
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
Fri Dec 21 11:47:56 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Fri Dec 21 11:35:10 2007 Koichi Sasada <ko1@atdot.net>
|
Fri Dec 21 11:35:10 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* vm.c, vm_dump.c: fix typo. Reported by Yuki Mitsui.
|
* vm.c, vm_dump.c: fix typo. Reported by Yuki Mitsui.
|
||||||
|
10
encoding.c
10
encoding.c
@ -14,6 +14,7 @@
|
|||||||
#include "ruby/encoding.h"
|
#include "ruby/encoding.h"
|
||||||
#include "regenc.h"
|
#include "regenc.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <langinfo.h>
|
||||||
|
|
||||||
static ID id_encoding, id_based_encoding;
|
static ID id_encoding, id_based_encoding;
|
||||||
static VALUE rb_cEncoding;
|
static VALUE rb_cEncoding;
|
||||||
@ -703,6 +704,14 @@ rb_enc_set_default_external(VALUE encoding)
|
|||||||
default_external_index = rb_enc_to_index(rb_to_encoding(encoding));
|
default_external_index = rb_enc_to_index(rb_to_encoding(encoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_locale_charmap(VALUE klass)
|
||||||
|
{
|
||||||
|
char *codeset;
|
||||||
|
codeset = nl_langinfo(CODESET);
|
||||||
|
return rb_str_new2(codeset);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_encoding_const(const char *name, rb_encoding *enc)
|
set_encoding_const(const char *name, rb_encoding *enc)
|
||||||
{
|
{
|
||||||
@ -772,6 +781,7 @@ Init_Encoding(void)
|
|||||||
rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1);
|
rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1);
|
||||||
|
|
||||||
rb_define_singleton_method(rb_cEncoding, "default_external", get_default_external, 0);
|
rb_define_singleton_method(rb_cEncoding, "default_external", get_default_external, 0);
|
||||||
|
rb_define_singleton_method(rb_cEncoding, "locale_charmap", rb_locale_charmap, 0);
|
||||||
|
|
||||||
/* dummy for unsupported, statefull encoding */
|
/* dummy for unsupported, statefull encoding */
|
||||||
rb_enc_replicate("ISO-2022-JP", rb_enc_find(rb_enc_name(ONIG_ENCODING_ASCII)));
|
rb_enc_replicate("ISO-2022-JP", rb_enc_find(rb_enc_name(ONIG_ENCODING_ASCII)));
|
||||||
|
@ -117,5 +117,6 @@ rb_encoding *rb_default_encoding(void);
|
|||||||
rb_encoding *rb_default_external_encoding(void);
|
rb_encoding *rb_default_external_encoding(void);
|
||||||
VALUE rb_enc_default_external(void);
|
VALUE rb_enc_default_external(void);
|
||||||
void rb_enc_set_default_external(VALUE encoding);
|
void rb_enc_set_default_external(VALUE encoding);
|
||||||
|
VALUE rb_locale_charmap(VALUE klass);
|
||||||
|
|
||||||
#endif /* RUBY_ENCODING_H */
|
#endif /* RUBY_ENCODING_H */
|
||||||
|
2
main.c
2
main.c
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#undef RUBY_EXPORT
|
#undef RUBY_EXPORT
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
RUBY_GLOBAL_SETUP
|
RUBY_GLOBAL_SETUP
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ main(int argc, char **argv, char **envp)
|
|||||||
extern void ruby_set_debug_option(const char *);
|
extern void ruby_set_debug_option(const char *);
|
||||||
ruby_set_debug_option(getenv("RUBY_DEBUG"));
|
ruby_set_debug_option(getenv("RUBY_DEBUG"));
|
||||||
#endif
|
#endif
|
||||||
|
setlocale(LC_CTYPE, "");
|
||||||
|
|
||||||
ruby_sysinit(&argc, &argv);
|
ruby_sysinit(&argc, &argv);
|
||||||
{
|
{
|
||||||
|
32
ruby.c
32
ruby.c
@ -138,32 +138,14 @@ usage(const char *name)
|
|||||||
static rb_encoding *
|
static rb_encoding *
|
||||||
locale_encoding(void)
|
locale_encoding(void)
|
||||||
{
|
{
|
||||||
static const char *const langs[] = {"LC_ALL", "LC_CTYPE", "LANG",};
|
VALUE codeset = rb_locale_charmap(Qnil);
|
||||||
const char *lang, *at;
|
char *name = StringValueCStr(codeset);
|
||||||
int i, len, idx = 0;
|
int idx;
|
||||||
char buf[32];
|
|
||||||
rb_encoding *enc;
|
|
||||||
|
|
||||||
for (i = 0; i < sizeof(langs) / sizeof(langs[0]); ++i) {
|
idx = rb_enc_find_index(name);
|
||||||
if (!(lang = getenv(langs[i]))) continue;
|
if (idx < 0)
|
||||||
if (!(lang = strchr(lang, '.'))) continue;
|
return rb_default_encoding();
|
||||||
at = strchr(++lang, '@');
|
return rb_enc_from_index(idx);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern VALUE rb_load_path;
|
extern VALUE rb_load_path;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user