* 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
This commit is contained in:
naruse 2009-10-28 07:34:24 +00:00
Родитель e2e09b8125
Коммит 7a884fe466
4 изменённых файлов: 60 добавлений и 35 удалений

Просмотреть файл

@ -1,3 +1,20 @@
Wed Oct 28 16:32:49 2009 NARUSE, Yui <naruse@ruby-lang.org>
* 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.
Wed Oct 28 15:02:31 2009 NARUSE, Yui <naruse@ruby-lang.org>
* gem_prelude.rb (Gem.set_home):

Просмотреть файл

@ -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_locale_encoding(void)
{
return rb_enc_from_index(rb_locale_encindex());
}
static int
rb_filesystem_encindex(void)
{
int idx;
#if defined NO_LOCALE_CHARMAP
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());
idx = rb_enc_find_index(cp);
#elif defined __APPLE__
idx = rb_utf8_encindex();
#else
idx = rb_locale_encindex();
#endif
if (rb_enc_registered("filesystem") < 0) enc_alias_internal("filesystem", idx);
return idx;
}
rb_encoding *
rb_filesystem_encoding(void)
{
rb_encoding *enc;
#if defined NO_LOCALE_CHARMAP
enc = 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);
#elif defined __APPLE__
enc = rb_utf8_encoding();
#else
enc = rb_locale_encoding();
#endif
return enc;
}
/*
* 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)
{
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);

Просмотреть файл

@ -67,7 +67,7 @@ if defined?(Gem) then
def self.set_home(home)
home = home.gsub File::ALT_SEPARATOR, File::SEPARATOR if File::ALT_SEPARATOR
@gem_home = home.force_encoding(Encoding.filesystem_encoding)
@gem_home = home.force_encoding(Encoding.find('filesystem'))
end
def self.set_paths(gpaths)
@ -87,7 +87,7 @@ if defined?(Gem) then
end
@gem_path.uniq!
@gem_path.map!{|x|x.force_encoding(Encoding.filesystem_encoding)}
@gem_path.map!{|x|x.force_encoding(Encoding.find('filesystem'))}
end
def self.user_home

Просмотреть файл

@ -37,6 +37,8 @@ class TestEncoding < Test::Unit::TestCase
def test_find
assert_raise(ArgumentError) { Encoding.find("foobarbazqux") }
assert_nothing_raised{Encoding.find("locale")}
assert_nothing_raised{Encoding.find("filesystem")}
end
def test_dummy_p