diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-30 12:54:15 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-30 12:54:15 +0000 |
commit | a2339bc02147505ae459293c9fece5ae17b5f285 (patch) | |
tree | 3f653f580e0222000c44f24f76112a67252968bc /encoding.c | |
parent | 4de39cd34edf69376af707071f0a6fbeed90e091 (diff) |
merges r25526,r25527,r25528,r25529,r25530 and r25555 from trunk into ruby_1_9_1.
--
* encoding.c (get_filesystem_encoding):
add Encoding.filesystem_encoding [ruby-dev:39546]
also see [ruby-core:25959]
--
* gem_prelude.rb (Gem.set_home):
force_encoding(Encoding.filesystem_encoding)
[ruby-dev:39546]
* gem_prelude.rb (Gem.set_paths): ditto.
--
Previous commit is for [ruby-core:25959]
--
* 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.
--
* encoding.c (enc_find): fixed rdoc formatting.
--
* ruby.c (process_options): call rb_filesystem_encoding().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@26510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'encoding.c')
-rw-r--r-- | encoding.c | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/encoding.c b/encoding.c index bc960c26a7..104d472eb6 100644 --- a/encoding.c +++ b/encoding.c @@ -921,9 +921,18 @@ 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. + * Only <code>Encoding.find("internal")</code> however returns nil + * when no encoding named "internal", in other words, when Ruby has no + * default internal encoding. */ static VALUE enc_find(VALUE klass, VALUE enc) @@ -1021,8 +1030,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; @@ -1034,25 +1043,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_enc_find("UTF8-MAC"); + idx = rb_enc_to_index(rb_enc_find("UTF8-MAC")); #else - enc = rb_default_external_encoding(); + idx = rb_enc_to_index(rb_default_external_encoding()); #endif - return enc; + + if (rb_enc_registered("filesystem") < 0) enc_alias_internal("filesystem", idx); + + return idx; +} + +rb_encoding * +rb_filesystem_encoding(void) +{ + return rb_enc_from_index(rb_filesystem_encindex()); } struct default_encoding { |