diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-24 07:01:22 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-24 07:01:22 +0000 |
commit | a31cc60806c5b7bacc25f580aa58d0cf492964b6 (patch) | |
tree | f8b7127db538d49542494b4db3aff93452d9b5ab /localeinit.c | |
parent | 7eb1afd57c30cc3c8964ad87993377cdad4e302f (diff) | |
download | ruby-a31cc60806c5b7bacc25f580aa58d0cf492964b6.tar.gz |
encoding.c: find encoding index
* encoding.c (rb_locale_encindex): find encoding index without
making a string object every time. [ruby-core:58160] [Bug #9080]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'localeinit.c')
-rw-r--r-- | localeinit.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/localeinit.c b/localeinit.c index a21b6b1a57..a5368ccc52 100644 --- a/localeinit.c +++ b/localeinit.c @@ -22,8 +22,8 @@ #define CP_FORMAT(buf, codepage) snprintf(buf, sizeof(buf), "CP%u", (codepage)) #endif -VALUE -rb_locale_charmap(VALUE klass) +static VALUE +locale_charmap(VALUE (*conv)(const char *)) { #if defined NO_LOCALE_CHARMAP # error NO_LOCALE_CHARMAP defined @@ -40,16 +40,34 @@ rb_locale_charmap(VALUE klass) CP_FORMAT(cp, codepage); codeset = cp; } - return rb_usascii_str_new2(codeset); + return (*conv)(codeset); #elif defined HAVE_LANGINFO_H char *codeset; codeset = nl_langinfo(CODESET); - return rb_usascii_str_new2(codeset); + return (*conv)(codeset); #else - return Qnil; + return ENCINDEX_US_ASCII; #endif } +VALUE +rb_locale_charmap(VALUE klass) +{ + return locale_charmap(rb_usascii_str_new_cstr); +} + +static VALUE +enc_find_index(const char *name) +{ + return (VALUE)rb_enc_find_index(name); +} + +int +rb_locale_charmap_index(VALUE klass) +{ + return (int)locale_charmap(enc_find_index); +} + int Init_enc_set_filesystem_encoding(void) { |