summaryrefslogtreecommitdiff
path: root/encoding.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-21 02:52:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-21 02:52:23 +0000
commit0530cf9ff88c13a69c95519139f75b87d097707c (patch)
tree34013f4a6bcb3b369f92fc26efb2af2c3ecccdaf /encoding.c
parent685cc0f7c4c85877ccbb2804bdbb15280b049445 (diff)
* 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
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/encoding.c b/encoding.c
index a85cfdfdf5..1e130162be 100644
--- a/encoding.c
+++ b/encoding.c
@@ -14,6 +14,7 @@
#include "ruby/encoding.h"
#include "regenc.h"
#include <ctype.h>
+#include <langinfo.h>
static ID id_encoding, id_based_encoding;
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));
}
+VALUE
+rb_locale_charmap(VALUE klass)
+{
+ char *codeset;
+ codeset = nl_langinfo(CODESET);
+ return rb_str_new2(codeset);
+}
+
static void
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, "default_external", get_default_external, 0);
+ rb_define_singleton_method(rb_cEncoding, "locale_charmap", rb_locale_charmap, 0);
/* dummy for unsupported, statefull encoding */
rb_enc_replicate("ISO-2022-JP", rb_enc_find(rb_enc_name(ONIG_ENCODING_ASCII)));