merges r30448 and r30498 from trunk into ruby_1_9_2.

--

* lib/irb/locale.rb (IRB::Locale#search_file): make it possible
  to load a localization from a gem.
  (IRB::Locale#lc_path): obsoleted because of the change of #search_file
  (IRB::Locale#each_localized_path): new private method, based on lc_path
  (IRB::Locale#find): follows the change of #search_file.
  (IRB::Locale#load): removed duplicate with #find.
--
* lib/irb/locale.rb (IRB::Locale::LOCALE_NAME_RE):
  some platoform has a locale without territory but with
  encoding.
  (#each_sub_locale): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@30563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
yugui 2011-01-16 12:34:36 +00:00
parent 67cabb2f17
commit e58b0f52b0
3 changed files with 56 additions and 53 deletions

View file

@ -1,3 +1,19 @@
Sun Jan 9 16:31:34 2011 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* lib/irb/locale.rb (IRB::Locale::LOCALE_NAME_RE):
some platoform has a locale without territory but with
encoding.
(#each_sub_locale): ditto.
Sat Jan 1 17:02:50 2011 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* lib/irb/locale.rb (IRB::Locale#search_file): make it possible
to load a localization from a gem.
(IRB::Locale#lc_path): obsoleted because of the change of #search_file
(IRB::Locale#each_localized_path): new private method, based on lc_path
(IRB::Locale#find): follows the change of #search_file.
(IRB::Locale#load): removed duplicate with #find.
Fri Dec 31 03:23:26 2010 NARUSE, Yui <naruse@ruby-lang.org> Fri Dec 31 03:23:26 2010 NARUSE, Yui <naruse@ruby-lang.org>
* vsnprintf.c (BSD__uqtoa): Fix overflow when long != quad_t. * vsnprintf.c (BSD__uqtoa): Fix overflow when long != quad_t.

View file

@ -13,16 +13,10 @@ module IRB
@RCS_ID='-$Id$-' @RCS_ID='-$Id$-'
LOCALE_NAME_RE = %r[ LOCALE_NAME_RE = %r[
(?<language>[[:alpha:]]{2}) (?<language>[[:alpha:]]{2,3})
(?:_ (?:_ (?<territory>[[:alpha:]]{2,3}) )?
(?<territory>[[:alpha:]]{2,3}) (?:\. (?<codeset>[^@]+) )?
(?:\. (?:@ (?<modifier>.*) )?
(?<codeset>[^@]+)
)?
)?
(?:@
(?<modifier>.*)
)?
]x ]x
LOCALE_DIR = "/lc/" LOCALE_DIR = "/lc/"
@ -50,7 +44,7 @@ module IRB
def String(mes) def String(mes)
mes = super(mes) mes = super(mes)
if @encoding if @encoding
mes.encode(@encoding) mes.encode(@encoding, undef: :replace)
else else
mes mes
end end
@ -111,22 +105,27 @@ module IRB
alias toplevel_load load alias toplevel_load load
def load(file, priv=nil) def load(file, priv=nil)
found = find(file)
if found
return real_load(found, priv)
else
raise LoadError, "No such file to load -- #{file}"
end
end
def find(file , paths = $:)
dir = File.dirname(file) dir = File.dirname(file)
dir = "" if dir == "." dir = "" if dir == "."
base = File.basename(file) base = File.basename(file)
if dir[0] == ?/ #/ if dir.start_with?('/')
lc_path = search_file(dir, base) return each_localized_path(dir, base).find{|full_path| File.readable? full_path}
return real_load(lc_path, priv) if lc_path else
return search_file(paths, dir, base)
end end
for path in $:
lc_path = search_file(path + "/" + dir, base)
return real_load(lc_path, priv) if lc_path
end
raise LoadError, "No such file to load -- #{file}"
end end
private
def real_load(path, priv) def real_load(path, priv)
src = MagicFile.open(path){|f| f.read} src = MagicFile.open(path){|f| f.read}
if priv if priv
@ -135,41 +134,30 @@ module IRB
eval(src, TOPLEVEL_BINDING, path) eval(src, TOPLEVEL_BINDING, path)
end end
end end
private :real_load
def find(file , paths = $:) # @param paths load paths in which IRB find a localized file.
dir = File.dirname(file) # @param dir directory
dir = "" if dir == "." # @param file basename to be localized
base = File.basename(file) #
if dir =~ /^\// # typically, for the parameters and a <path> in paths, it searches
return lc_path = search_file(dir, base) # <path>/<dir>/<locale>/<file>
else def search_file(lib_paths, dir, file)
for path in $: each_localized_path(dir, file) do |lc_path|
if lc_path = search_file(path + "/" + dir, base) lib_paths.each do |libpath|
return lc_path full_path = File.join(libpath, lc_path)
end return full_path if File.readable?(full_path)
end end
redo if Gem.try_activate(lc_path)
end end
nil nil
end end
def search_file(path, file) def each_localized_path(dir, file)
return enum_for(:each_localized_path) unless block_given?
each_sublocale do |lc| each_sublocale do |lc|
full_path = path + lc_path(file, lc) yield lc.nil? ? File.join(dir, LOCALE_DIR, file) : File.join(dir, LOCALE_DIR, lc, file)
return full_path if File.exist?(full_path)
end
nil
end
private :search_file
def lc_path(file = "", lc = @locale)
if lc.nil?
LOCALE_DIR + file
else
LOCALE_DIR + @lang + "/" + file
end end
end end
private :lc_path
def each_sublocale def each_sublocale
if @lang if @lang
@ -181,15 +169,14 @@ module IRB
yield "#{@lang}_#{@territory}@#{@modifier}" if @modifier yield "#{@lang}_#{@territory}@#{@modifier}" if @modifier
yield "#{@lang}_#{@territory}" yield "#{@lang}_#{@territory}"
end end
if @encoding_name
yield "#{@lang}.#{@encoding_name}@#{@modifier}" if @modifier
yield "#{@lang}.#{@encoding_name}"
end
yield "#{@lang}@#{@modifier}" if @modifier yield "#{@lang}@#{@modifier}" if @modifier
yield "#{@lang}" yield "#{@lang}"
end end
yield nil yield nil
end end
private :each_sublocale
end end
end end

View file

@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.2" #define RUBY_VERSION "1.9.2"
#define RUBY_PATCHLEVEL 143 #define RUBY_PATCHLEVEL 144
#define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_MINOR 9
#define RUBY_VERSION_TEENY 1 #define RUBY_VERSION_TEENY 1