ruby-changes:13736
From: naruse <ko1@a...>
Date: Wed, 28 Oct 2009 16:34:46 +0900 (JST)
Subject: [ruby-changes:13736] Ruby:r25529 (trunk): * encoding.c (get_filesystem_encoding): removed.
naruse 2009-10-28 16:34:24 +0900 (Wed, 28 Oct 2009) New Revision: 25529 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25529 Log: * 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. Modified files: trunk/ChangeLog trunk/encoding.c trunk/gem_prelude.rb trunk/test/ruby/test_encoding.rb Index: encoding.c =================================================================== --- encoding.c (revision 25528) +++ encoding.c (revision 25529) @@ -984,6 +984,14 @@ * 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 @@ 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 @@ 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 @@ 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); Index: ChangeLog =================================================================== --- ChangeLog (revision 25528) +++ ChangeLog (revision 25529) @@ -1,3 +1,20 @@ +Wed Oct 28 16:32:49 2009 NARUSE, Yui <naruse@r...> + + * 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@r...> * gem_prelude.rb (Gem.set_home): Index: gem_prelude.rb =================================================================== --- gem_prelude.rb (revision 25528) +++ gem_prelude.rb (revision 25529) @@ -67,7 +67,7 @@ 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 @@ 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 Index: test/ruby/test_encoding.rb =================================================================== --- test/ruby/test_encoding.rb (revision 25528) +++ test/ruby/test_encoding.rb (revision 25529) @@ -37,6 +37,8 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/