rubysl-irb 1.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/lib/irb/cmd/chws.rb +6 -6
  4. data/lib/irb/cmd/fork.rb +10 -10
  5. data/lib/irb/cmd/help.rb +24 -14
  6. data/lib/irb/cmd/load.rb +8 -7
  7. data/lib/irb/cmd/nop.rb +8 -8
  8. data/lib/irb/cmd/pushws.rb +6 -5
  9. data/lib/irb/cmd/subirb.rb +6 -7
  10. data/lib/irb/completion.rb +90 -58
  11. data/lib/irb/context.rb +197 -30
  12. data/lib/irb/ext/change-ws.rb +17 -10
  13. data/lib/irb/ext/history.rb +20 -10
  14. data/lib/irb/ext/loader.rb +22 -12
  15. data/lib/irb/ext/math-mode.rb +16 -6
  16. data/lib/irb/ext/multi-irb.rb +69 -24
  17. data/lib/irb/ext/save-history.rb +87 -37
  18. data/lib/irb/ext/tracer.rb +17 -7
  19. data/lib/irb/ext/use-loader.rb +14 -6
  20. data/lib/irb/ext/workspaces.rb +16 -6
  21. data/lib/irb/extend-command.rb +92 -34
  22. data/lib/irb/frame.rb +18 -5
  23. data/lib/irb/help.rb +20 -19
  24. data/lib/irb/init.rb +156 -104
  25. data/lib/irb/input-method.rb +96 -23
  26. data/lib/irb/inspector.rb +145 -0
  27. data/lib/irb/lc/.document +4 -0
  28. data/lib/irb/lc/error.rb +8 -7
  29. data/lib/irb/lc/{help-message.rb → help-message} +14 -11
  30. data/lib/irb/lc/ja/encoding_aliases.rb +10 -0
  31. data/lib/irb/lc/ja/error.rb +19 -16
  32. data/lib/irb/lc/ja/help-message +33 -28
  33. data/lib/irb/locale.rb +83 -85
  34. data/lib/irb/magic-file.rb +37 -0
  35. data/lib/irb/notifier.rb +101 -15
  36. data/lib/irb/output-method.rb +38 -32
  37. data/lib/irb/ruby-lex.rb +143 -81
  38. data/lib/irb/ruby-token.rb +13 -19
  39. data/lib/irb/slex.rb +26 -27
  40. data/lib/irb/src_encoding.rb +4 -0
  41. data/lib/irb/version.rb +6 -7
  42. data/lib/irb/workspace.rb +22 -15
  43. data/lib/irb/ws-for-case-2.rb +5 -6
  44. data/lib/irb/xmp.rb +91 -4
  45. data/lib/rubysl/irb/irb.rb +523 -175
  46. data/lib/rubysl/irb/version.rb +1 -1
  47. data/rubysl-irb.gemspec +7 -6
  48. metadata +35 -15
@@ -0,0 +1,145 @@
1
+ #
2
+ # irb/inspector.rb - inspect methods
3
+ # $Release Version: 0.9.6$
4
+ # $Revision: 1.19 $
5
+ # $Date: 2002/06/11 07:51:31 $
6
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
+ #
8
+ # --
9
+ #
10
+ #
11
+ #
12
+
13
+ module IRB # :nodoc:
14
+
15
+
16
+ # Convenience method to create a new Inspector, using the given +inspect+
17
+ # proc, and optional +init+ proc and passes them to Inspector.new
18
+ #
19
+ # irb(main):001:0> ins = IRB::Inspector(proc{ |v| "omg! #{v}" })
20
+ # irb(main):001:0> IRB.CurrentContext.inspect_mode = ins # => omg! #<IRB::Inspector:0x007f46f7ba7d28>
21
+ # irb(main):001:0> "what?" #=> omg! what?
22
+ #
23
+ def IRB::Inspector(inspect, init = nil)
24
+ Inspector.new(inspect, init)
25
+ end
26
+
27
+ # An irb inspector
28
+ #
29
+ # In order to create your own custom inspector there are two things you
30
+ # should be aware of:
31
+ #
32
+ # Inspector uses #inspect_value, or +inspect_proc+, for output of return values.
33
+ #
34
+ # This also allows for an optional #init+, or +init_proc+, which is called
35
+ # when the inspector is activated.
36
+ #
37
+ # Knowing this, you can create a rudimentary inspector as follows:
38
+ #
39
+ # irb(main):001:0> ins = IRB::Inspector.new(proc{ |v| "omg! #{v}" })
40
+ # irb(main):001:0> IRB.CurrentContext.inspect_mode = ins # => omg! #<IRB::Inspector:0x007f46f7ba7d28>
41
+ # irb(main):001:0> "what?" #=> omg! what?
42
+ #
43
+ class Inspector
44
+ # Default inspectors available to irb, this includes:
45
+ #
46
+ # +:pp+:: Using Kernel#pretty_inspect
47
+ # +:yaml+:: Using YAML.dump
48
+ # +:marshal+:: Using Marshal.dump
49
+ INSPECTORS = {}
50
+
51
+ # Determines the inspector to use where +inspector+ is one of the keys passed
52
+ # during inspector definition.
53
+ def self.keys_with_inspector(inspector)
54
+ INSPECTORS.select{|k,v| v == inspector}.collect{|k, v| k}
55
+ end
56
+
57
+ # Example
58
+ #
59
+ # Inspector.def_inspector(key, init_p=nil){|v| v.inspect}
60
+ # Inspector.def_inspector([key1,..], init_p=nil){|v| v.inspect}
61
+ # Inspector.def_inspector(key, inspector)
62
+ # Inspector.def_inspector([key1,...], inspector)
63
+ def self.def_inspector(key, arg=nil, &block)
64
+ # if !block_given?
65
+ # case arg
66
+ # when nil, Proc
67
+ # inspector = IRB::Inspector(init_p)
68
+ # when Inspector
69
+ # inspector = init_p
70
+ # else
71
+ # IRB.Raise IllegalParameter, init_p
72
+ # end
73
+ # init_p = nil
74
+ # else
75
+ # inspector = IRB::Inspector(block, init_p)
76
+ # end
77
+
78
+ if block_given?
79
+ inspector = IRB::Inspector(block, arg)
80
+ else
81
+ inspector = arg
82
+ end
83
+
84
+ case key
85
+ when Array
86
+ for k in key
87
+ def_inspector(k, inspector)
88
+ end
89
+ when Symbol
90
+ INSPECTORS[key] = inspector
91
+ INSPECTORS[key.to_s] = inspector
92
+ when String
93
+ INSPECTORS[key] = inspector
94
+ INSPECTORS[key.intern] = inspector
95
+ else
96
+ INSPECTORS[key] = inspector
97
+ end
98
+ end
99
+
100
+ # Creates a new inspector object, using the given +inspect_proc+ when
101
+ # output return values in irb.
102
+ def initialize(inspect_proc, init_proc = nil)
103
+ @init = init_proc
104
+ @inspect = inspect_proc
105
+ end
106
+
107
+ # Proc to call when the inspector is activated, good for requiring
108
+ # dependant libraries.
109
+ def init
110
+ @init.call if @init
111
+ end
112
+
113
+ # Proc to call when the input is evaluated and output in irb.
114
+ def inspect_value(v)
115
+ @inspect.call(v)
116
+ end
117
+ end
118
+
119
+ Inspector.def_inspector([false, :to_s, :raw]){|v| v.to_s}
120
+ Inspector.def_inspector([true, :p, :inspect]){|v|
121
+ begin
122
+ v.inspect
123
+ rescue NoMethodError
124
+ puts "(Object doesn't support #inspect)"
125
+ end
126
+ }
127
+ Inspector.def_inspector([:pp, :pretty_inspect], proc{require "pp"}){|v| v.pretty_inspect.chomp}
128
+ Inspector.def_inspector([:yaml, :YAML], proc{require "yaml"}){|v|
129
+ begin
130
+ YAML.dump(v)
131
+ rescue
132
+ puts "(can't dump yaml. use inspect)"
133
+ v.inspect
134
+ end
135
+ }
136
+
137
+ Inspector.def_inspector([:marshal, :Marshal, :MARSHAL, Marshal]){|v|
138
+ Marshal.dump(v)
139
+ }
140
+ end
141
+
142
+
143
+
144
+
145
+
@@ -0,0 +1,4 @@
1
+ # hide help-message files which contain usage information
2
+ error.rb
3
+ ja/encoding_aliases.rb
4
+ ja/error.rb
data/lib/irb/lc/error.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  #
2
- # irb/lc/error.rb -
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
2
+ # irb/lc/error.rb -
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
9
+ #
11
10
  #
12
11
  require "e2mmap"
13
12
 
13
+ # :stopdoc:
14
14
  module IRB
15
15
 
16
16
  # exceptions
@@ -18,13 +18,14 @@ module IRB
18
18
  def_exception :UnrecognizedSwitch, "Unrecognized switch: %s"
19
19
  def_exception :NotImplementedError, "Need to define `%s'"
20
20
  def_exception :CantReturnToNormalMode, "Can't return to normal mode."
21
- def_exception :IllegalParameter, "Illegal parameter(%s)."
21
+ def_exception :IllegalParameter, "Invalid parameter(%s)."
22
22
  def_exception :IrbAlreadyDead, "Irb is already dead."
23
23
  def_exception :IrbSwitchedToCurrentThread, "Switched to current thread."
24
24
  def_exception :NoSuchJob, "No such job(%s)."
25
25
  def_exception :CantShiftToMultiIrbMode, "Can't shift to multi irb mode."
26
26
  def_exception :CantChangeBinding, "Can't change binding to (%s)."
27
27
  def_exception :UndefinedPromptMode, "Undefined prompt mode(%s)."
28
+ def_exception :IllegalRCGenerator, 'Define illegal RC_NAME_GENERATOR.'
28
29
 
29
30
  end
30
-
31
+ # :startdoc:
@@ -1,21 +1,24 @@
1
+ # -*- coding: US-ASCII -*-
1
2
  #
2
- # irb/lc/help-message.rb -
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
3
+ # irb/lc/help-message.rb -
4
+ # $Release Version: 0.9.6$
5
+ # $Revision$
6
6
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
7
  #
8
8
  # --
9
9
  #
10
- #
11
10
  #
12
- <<HELP
11
+ #
13
12
  Usage: irb.rb [options] [programfile] [arguments]
14
- -f Suppress read of ~/.irbrc
13
+ -f Suppress read of ~/.irbrc
15
14
  -m Bc mode (load mathn, fraction or matrix are available)
16
15
  -d Set $DEBUG to true (same as `ruby -d')
17
16
  -r load-module Same as `ruby -r'
18
17
  -I path Specify $LOAD_PATH directory
18
+ -U Same as `ruby -U`
19
+ -E enc Same as `ruby -E`
20
+ -w Same as `ruby -w`
21
+ -W[level=2] Same as `ruby -W`
19
22
  --inspect Use `inspect' for output (default except for bc mode)
20
23
  --noinspect Don't use inspect for output
21
24
  --readline Use Readline extension module
@@ -24,14 +27,14 @@ Usage: irb.rb [options] [programfile] [arguments]
24
27
  --prompt-mode prompt-mode
25
28
  Switch prompt mode. Pre-defined prompt modes are
26
29
  `default', `simple', `xmp' and `inf-ruby'
27
- --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
28
- Suppresses --readline.
30
+ --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
31
+ Suppresses --readline.
29
32
  --simple-prompt Simple prompt mode
30
33
  --noprompt No prompt mode
31
34
  --tracer Display trace for each execution of commands.
32
35
  --back-trace-limit n
33
36
  Display backtrace top n and tail n. The default
34
- value is 16.
37
+ value is 16.
35
38
  --irb_debug n Set internal debug level to n (not for popular use)
36
39
  -v, --version Print the version of irb
37
- HELP
40
+ # vim:fileencoding=us-ascii
@@ -0,0 +1,10 @@
1
+ # :stopdoc:
2
+ module IRB
3
+ class Locale
4
+ @@legacy_encoding_alias_map = {
5
+ 'ujis' => Encoding::EUC_JP,
6
+ 'euc' => Encoding::EUC_JP
7
+ }.freeze
8
+ end
9
+ end
10
+ # :startdoc:
@@ -1,27 +1,30 @@
1
- #
2
- # irb/lc/ja/error.rb -
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
1
+ # -*- coding: utf-8 -*-
2
+ # irb/lc/ja/error.rb -
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
9
+ #
11
10
  #
12
11
  require "e2mmap"
13
12
 
13
+ # :stopdoc:
14
14
  module IRB
15
15
  # exceptions
16
16
  extend Exception2MessageMapper
17
- def_exception :UnrecognizedSwitch, '$B%9%$%C%A(B(%s)$B$,J,$j$^$;$s(B'
18
- def_exception :NotImplementedError, '`%s\'$B$NDj5A$,I,MW$G$9(B'
19
- def_exception :CantReturnToNormalMode, 'Normal$B%b!<%I$KLa$l$^$;$s(B.'
20
- def_exception :IllegalParameter, '$B%Q%i%a!<%?(B(%s)$B$,4V0c$C$F$$$^$9(B.'
21
- def_exception :IrbAlreadyDead, 'Irb$B$O4{$K;`$s$G$$$^$9(B.'
22
- def_exception :IrbSwitchedToCurrentThread, '$B%+%l%s%H%9%l%C%I$K@Z$jBX$o$j$^$7$?(B.'
23
- def_exception :NoSuchJob, '$B$=$N$h$&$J%8%g%V(B(%s)$B$O$"$j$^$;$s(B.'
24
- def_exception :CantShiftToMultiIrbMode, 'multi-irb mode$B$K0\$l$^$;$s(B.'
25
- def_exception :CantChangeBinding, '$B%P%$%s%G%#%s%0(B(%s)$B$KJQ99$G$-$^$;$s(B.'
26
- def_exception :UndefinedPromptMode, '$B%W%m%s%W%H%b!<%I(B(%s)$B$ODj5A$5$l$F$$$^$;$s(B.'
17
+ def_exception :UnrecognizedSwitch, 'スイッチ(%s)が分りません'
18
+ def_exception :NotImplementedError, '`%s\'の定義が必要です'
19
+ def_exception :CantReturnToNormalMode, 'Normalモードに戻れません.'
20
+ def_exception :IllegalParameter, 'パラメータ(%s)が間違っています.'
21
+ def_exception :IrbAlreadyDead, 'Irbは既に死んでいます.'
22
+ def_exception :IrbSwitchedToCurrentThread, 'カレントスレッドに切り替わりました.'
23
+ def_exception :NoSuchJob, 'そのようなジョブ(%s)はありません.'
24
+ def_exception :CantShiftToMultiIrbMode, 'multi-irb modeに移れません.'
25
+ def_exception :CantChangeBinding, 'バインディング(%s)に変更できません.'
26
+ def_exception :UndefinedPromptMode, 'プロンプトモード(%s)は定義されていません.'
27
+ def_exception :IllegalRCNameGenerator, 'RC_NAME_GENERATORが正しく定義されていません.'
27
28
  end
29
+ # :startdoc:
30
+ # vim:fileencoding=utf-8
@@ -1,36 +1,41 @@
1
- #
2
- # irb/lc/ja/help-message.rb -
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
1
+ # -*- coding: utf-8 -*-
2
+ # irb/lc/ja/help-message.rb -
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
9
+ #
11
10
  #
12
11
  Usage: irb.rb [options] [programfile] [arguments]
13
- -f ~/.irbrc $B$rFI$_9~$^$J$$(B.
14
- -m bc$B%b!<%I(B($BJ,?t(B, $B9TNs$N7W;;$,$G$-$k(B)
15
- -d $DEBUG $B$r(Btrue$B$K$9$k(B(ruby -d $B$HF1$8(B)
16
- -r load-module ruby -r $B$HF1$8(B.
17
- -I path $LOAD_PATH $B$K(B path $B$rDI2C$9$k(B.
18
- --inspect $B7k2L=PNO$K(Binspect$B$rMQ$$$k(B(bc$B%b!<%I0J30$O%G%U%)%k%H(B).
19
- --noinspect $B7k2L=PNO$K(Binspect$B$rMQ$$$J$$(B.
20
- --readline readline$B%i%$%V%i%j$rMxMQ$9$k(B.
21
- --noreadline readline$B%i%$%V%i%j$rMxMQ$7$J$$(B.
12
+ -f ~/.irbrc を読み込まない.
13
+ -m bcモード(分数, 行列の計算ができる)
14
+ -d $DEBUG をtrueにする(ruby -d と同じ)
15
+ -r load-module ruby -r と同じ.
16
+ -I path $LOAD_PATH path を追加する.
17
+ -U ruby -U と同じ.
18
+ -E enc ruby -E と同じ.
19
+ -w ruby -w と同じ.
20
+ -W[level=2] ruby -W と同じ.
21
+ --inspect 結果出力にinspectを用いる(bcモード以外はデフォルト).
22
+ --noinspect 結果出力にinspectを用いない.
23
+ --readline readlineライブラリを利用する.
24
+ --noreadline readlineライブラリを利用しない.
22
25
  --prompt prompt-mode/--prompt-mode prompt-mode
23
- $B%W%m%s%W%H%b!<%I$r@ZBX$($^$9(B. $B8=:_Dj5A$5$l$F$$$k%W(B
24
- $B%m%s%W%H%b!<%I$O(B, default, simple, xmp, inf-ruby$B$,(B
25
- $BMQ0U$5$l$F$$$^$9(B.
26
- --inf-ruby-mode emacs$B$N(Binf-ruby-mode$BMQ$N%W%m%s%W%HI=<($r9T$J$&(B. $BFC(B
27
- $B$K;XDj$,$J$$8B$j(B, readline$B%i%$%V%i%j$O;H$o$J$/$J$k(B.
28
- --simple-prompt $BHs>o$K%7%s%W%k$J%W%m%s%W%H$rMQ$$$k%b!<%I$G$9(B.
29
- --noprompt $B%W%m%s%W%HI=<($r9T$J$o$J$$(B.
30
- --tracer $B%3%^%s%I<B9T;~$K%H%l!<%9$r9T$J$&(B.
26
+ プロンプトモードを切替えます. 現在定義されているプ
27
+ ロンプトモードは, default, simple, xmp, inf-ruby
28
+ 用意されています.
29
+ --inf-ruby-mode emacsのinf-ruby-mode用のプロンプト表示を行なう.
30
+ に指定がない限り, readlineライブラリは使わなくなる.
31
+ --simple-prompt 非常にシンプルなプロンプトを用いるモードです.
32
+ --noprompt プロンプト表示を行なわない.
33
+ --tracer コマンド実行時にトレースを行なう.
31
34
  --back-trace-limit n
32
- $B%P%C%/%H%l!<%9I=<($r%P%C%/%H%l!<%9$NF,$+$i(B n, $B8e$m(B
33
- $B$+$i(Bn$B$@$19T$J$&(B. $B%G%U%)%k%H$O(B16
34
- --irb_debug n irb$B$N%G%P%C%0%G%P%C%0%l%Y%k$r(Bn$B$K@_Dj$9$k(B($BMxMQ$7$J(B
35
- $B$$J}$,L5Fq$G$7$g$&(B).
36
- -v, --version irb$B$N%P!<%8%g%s$rI=<($9$k(B
35
+ バックトレース表示をバックトレースの頭から n, 後ろ
36
+ からnだけ行なう. デフォルトは16
37
+ --irb_debug n irbのデバッグデバッグレベルをnに設定する(利用しな
38
+ い方が無難でしょう).
39
+ -v, --version irbのバージョンを表示する
40
+
41
+ # vim:fileencoding=utf-8
data/lib/irb/locale.rb CHANGED
@@ -1,51 +1,53 @@
1
1
  #
2
2
  # irb/locale.rb - internationalization module
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
11
9
  #
12
-
13
- autoload :Kconv, "kconv"
14
-
15
- module IRB
10
+ #
11
+ module IRB # :nodoc:
16
12
  class Locale
17
- @RCS_ID='-$Id: locale.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
18
-
19
- JPDefaultLocale = "ja"
13
+ @RCS_ID='-$Id$-'
14
+
15
+ LOCALE_NAME_RE = %r[
16
+ (?<language>[[:alpha:]]{2,3})
17
+ (?:_ (?<territory>[[:alpha:]]{2,3}) )?
18
+ (?:\. (?<codeset>[^@]+) )?
19
+ (?:@ (?<modifier>.*) )?
20
+ ]x
20
21
  LOCALE_DIR = "/lc/"
21
22
 
22
- def initialize(locale = nil)
23
- @lang = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
24
- end
23
+ @@legacy_encoding_alias_map = {}.freeze
25
24
 
26
- attr_reader :lang
27
-
28
- def lc2kconv(lang)
29
- case lang
30
- when "ja_JP.ujis", "ja_JP.euc", "ja_JP.eucJP"
31
- Kconv::EUC
32
- when "ja_JP.sjis", "ja_JP.SJIS"
33
- Kconv::SJIS
34
- when /ja_JP.utf-?8/i
35
- Kconv::UTF8
25
+ def initialize(locale = nil)
26
+ @lang = @territory = @encoding_name = @modifier = nil
27
+ @locale = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
28
+ if m = LOCALE_NAME_RE.match(@locale)
29
+ @lang, @territory, @encoding_name, @modifier = m[:language], m[:territory], m[:codeset], m[:modifier]
30
+
31
+ if @encoding_name
32
+ begin load 'irb/encoding_aliases.rb'; rescue LoadError; end
33
+ if @encoding = @@legacy_encoding_alias_map[@encoding_name]
34
+ warn "%s is obsolete. use %s" % ["#{@lang}_#{@territory}.#{@encoding_name}", "#{@lang}_#{@territory}.#{@encoding.name}"]
35
+ end
36
+ @encoding = Encoding.find(@encoding_name) rescue nil
37
+ end
36
38
  end
39
+ @encoding ||= (Encoding.find('locale') rescue Encoding::ASCII_8BIT)
37
40
  end
38
- private :lc2kconv
41
+
42
+ attr_reader :lang, :territory, :encoding, :modifieer
39
43
 
40
44
  def String(mes)
41
45
  mes = super(mes)
42
- case @lang
43
- when /^ja/
44
- mes = Kconv::kconv(mes, lc2kconv(@lang))
46
+ if @encoding
47
+ mes.encode(@encoding, undef: :replace)
45
48
  else
46
49
  mes
47
50
  end
48
- mes
49
51
  end
50
52
 
51
53
  def format(*opts)
@@ -101,84 +103,80 @@ module IRB
101
103
  end
102
104
 
103
105
  alias toplevel_load load
104
-
106
+
105
107
  def load(file, priv=nil)
108
+ found = find(file)
109
+ if found
110
+ return real_load(found, priv)
111
+ else
112
+ raise LoadError, "No such file to load -- #{file}"
113
+ end
114
+ end
115
+
116
+ def find(file , paths = $:)
106
117
  dir = File.dirname(file)
107
118
  dir = "" if dir == "."
108
119
  base = File.basename(file)
109
120
 
110
- if /^ja(_JP)?$/ =~ @lang
111
- back, @lang = @lang, "C"
112
- end
113
- begin
114
- if dir[0] == ?/ #/
115
- lc_path = search_file(dir, base)
116
- return real_load(lc_path, priv) if lc_path
117
- end
118
-
119
- for path in $:
120
- lc_path = search_file(path + "/" + dir, base)
121
- return real_load(lc_path, priv) if lc_path
122
- end
123
- ensure
124
- @lang = back if back
121
+ if dir.start_with?('/')
122
+ return each_localized_path(dir, base).find{|full_path| File.readable? full_path}
123
+ else
124
+ return search_file(paths, dir, base)
125
125
  end
126
- raise LoadError, "No such file to load -- #{file}"
127
- end
126
+ end
128
127
 
128
+ private
129
129
  def real_load(path, priv)
130
- src = self.String(File.read(path))
130
+ src = MagicFile.open(path){|f| f.read}
131
131
  if priv
132
132
  eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)})
133
133
  else
134
134
  eval(src, TOPLEVEL_BINDING, path)
135
135
  end
136
136
  end
137
- private :real_load
138
137
 
139
- def find(file , paths = $:)
140
- dir = File.dirname(file)
141
- dir = "" if dir == "."
142
- base = File.basename(file)
143
- if dir[0] == ?/ #/
144
- return lc_path = search_file(dir, base)
145
- else
146
- for path in $:
147
- if lc_path = search_file(path + "/" + dir, base)
148
- return lc_path
149
- end
150
- end
138
+ # @param paths load paths in which IRB find a localized file.
139
+ # @param dir directory
140
+ # @param file basename to be localized
141
+ #
142
+ # typically, for the parameters and a <path> in paths, it searches
143
+ # <path>/<dir>/<locale>/<file>
144
+ def search_file(lib_paths, dir, file)
145
+ each_localized_path(dir, file) do |lc_path|
146
+ lib_paths.each do |libpath|
147
+ full_path = File.join(libpath, lc_path)
148
+ return full_path if File.readable?(full_path)
149
+ end
150
+ redo if defined?(Gem) and Gem.try_activate(lc_path)
151
151
  end
152
152
  nil
153
153
  end
154
154
 
155
- def search_file(path, file)
156
- if File.exist?(p1 = path + lc_path(file, "C"))
157
- if File.exist?(p2 = path + lc_path(file))
158
- return p2
159
- else
160
- end
161
- return p1
162
- else
155
+ def each_localized_path(dir, file)
156
+ return enum_for(:each_localized_path) unless block_given?
157
+ each_sublocale do |lc|
158
+ yield lc.nil? ? File.join(dir, LOCALE_DIR, file) : File.join(dir, LOCALE_DIR, lc, file)
163
159
  end
164
- nil
165
160
  end
166
- private :search_file
167
-
168
- def lc_path(file = "", lc = @lang)
169
- case lc
170
- when "C"
171
- LOCALE_DIR + file
172
- when /^ja/
173
- LOCALE_DIR + "ja/" + file
174
- else
175
- LOCALE_DIR + @lang + "/" + file
161
+
162
+ def each_sublocale
163
+ if @lang
164
+ if @territory
165
+ if @encoding_name
166
+ yield "#{@lang}_#{@territory}.#{@encoding_name}@#{@modifier}" if @modifier
167
+ yield "#{@lang}_#{@territory}.#{@encoding_name}"
168
+ end
169
+ yield "#{@lang}_#{@territory}@#{@modifier}" if @modifier
170
+ yield "#{@lang}_#{@territory}"
171
+ end
172
+ if @encoding_name
173
+ yield "#{@lang}.#{@encoding_name}@#{@modifier}" if @modifier
174
+ yield "#{@lang}.#{@encoding_name}"
175
+ end
176
+ yield "#{@lang}@#{@modifier}" if @modifier
177
+ yield "#{@lang}"
176
178
  end
179
+ yield nil
177
180
  end
178
- private :lc_path
179
181
  end
180
182
  end
181
-
182
-
183
-
184
-