aboutsummaryrefslogtreecommitdiffstats
path: root/encoding.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-28 07:34:24 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-28 07:34:24 +0000
commit7a884fe4660746a085bc999c9c35e2e1833ae136 (patch)
tree0985c3b432314833a40f333a82ee28d3beda49f7 /encoding.c
parente2e09b812541c629f52ae89ae7de7bb1945f3420 (diff)
downloadruby-7a884fe4660746a085bc999c9c35e2e1833ae136.tar.gz
* encoding.c (get_filesystem_encoding): removed.
* encoding.c (rb_locale_encindex): added. * encoding.c (rb_filesystem_encindex): added. * encoding.c (rb_filesystem_encindex): add an alias 'filesystem'. [ruby-dev:39574] * encoding.c (enc_find): add rdoc about special aliases. * gem_prelude.rb (Gem.set_home): use Encoding.find('filesystem'). * gem_prelude.rb (Gem.set_paths): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/encoding.c b/encoding.c
index b02aa7c566..45c63927e8 100644
--- a/encoding.c
+++ b/encoding.c
@@ -984,6 +984,14 @@ enc_list(VALUE klass)
* Encoding.find("US-ASCII") => #<Encoding:US-ASCII>
* Encoding.find(:Shift_JIS) => #<Encoding:Shift_JIS>
*
+ * Names which this method accept are encoding names and aliases
+ * including following special aliases
+ *
+ * * external (default external encoding)
+ * * internal (default internal encoding)
+ * * locale (locale encoding)
+ * * filesystem (filesystem encoding)
+ *
* An ArgumentError is raised when no encoding with <i>name</i>.
* Only +Encoding.find("internal")+ however returns nil when no encoding named "internal",
* in other words, when Ruby has no default internal encoding.
@@ -1084,8 +1092,8 @@ rb_usascii_encindex(void)
return ENCINDEX_US_ASCII;
}
-rb_encoding *
-rb_locale_encoding(void)
+static int
+rb_locale_encindex(void)
{
VALUE charmap = rb_locale_charmap(rb_cEncoding);
int idx;
@@ -1097,41 +1105,40 @@ rb_locale_encoding(void)
if (rb_enc_registered("locale") < 0) enc_alias_internal("locale", idx);
- return rb_enc_from_index(idx);
+ return idx;
}
rb_encoding *
-rb_filesystem_encoding(void)
+rb_locale_encoding(void)
{
- rb_encoding *enc;
+ return rb_enc_from_index(rb_locale_encindex());
+}
+
+static int
+rb_filesystem_encindex(void)
+{
+ int idx;
#if defined NO_LOCALE_CHARMAP
- enc = rb_default_external_encoding();
+ idx = rb_enc_to_index(rb_default_external_encoding());
#elif defined _WIN32 || defined __CYGWIN__
char cp[sizeof(int) * 8 / 3 + 4];
snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
- enc = rb_enc_find(cp);
+ idx = rb_enc_find_index(cp);
#elif defined __APPLE__
- enc = rb_utf8_encoding();
+ idx = rb_utf8_encindex();
#else
- enc = rb_locale_encoding();
+ idx = rb_locale_encindex();
#endif
- return enc;
+
+ if (rb_enc_registered("filesystem") < 0) enc_alias_internal("filesystem", idx);
+
+ return idx;
}
-/*
- * call-seq:
- * Encoding.filesystem_encoding => enc
- *
- * Returns filesystem encoding.
- *
- * It is locale encoding on Unix,
- * the currrent ANSI (or OEM unless AreFileApisANSI) code page on Windows,
- * UTF-8 on Mac OS X.
- */
-static VALUE
-get_filesystem_encoding(VALUE klass)
+rb_encoding *
+rb_filesystem_encoding(void)
{
- return rb_enc_from_encoding(rb_filesystem_encoding());
+ return rb_enc_from_index(rb_filesystem_encindex());
}
struct default_encoding {
@@ -1479,7 +1486,6 @@ Init_Encoding(void)
rb_define_method(rb_cEncoding, "_dump", enc_dump, -1);
rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1);
- rb_define_singleton_method(rb_cEncoding, "filesystem_encoding", get_filesystem_encoding, 0);
rb_define_singleton_method(rb_cEncoding, "default_external", get_default_external, 0);
rb_define_singleton_method(rb_cEncoding, "default_external=", set_default_external, 1);
rb_define_singleton_method(rb_cEncoding, "default_internal", get_default_internal, 0);