diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-07-05 05:55:58 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-07-05 05:55:58 +0000 |
commit | 69100ebb4d8fc48c985061631d09a01a2c6b2b82 (patch) | |
tree | 4b1223c94538d16ba68ef6f1ce74491e310a1011 /ext/tk/lib | |
parent | 648ac9b2416c00ab70b5a1c0f39950a55c91120b (diff) | |
download | ruby-69100ebb4d8fc48c985061631d09a01a2c6b2b82.tar.gz ruby-69100ebb4d8fc48c985061631d09a01a2c6b2b82.tar.xz ruby-69100ebb4d8fc48c985061631d09a01a2c6b2b82.zip |
* ext/tcltklib/tcltklib.c: bug fix on treating Unicode strings.
* ext/tcltklib/tcltklib.c: add methods to treat encoding mode.
* ext/tcltklib/MANUAL.eng: add description of TclTkLib#encoding,
encoding_system, and so on.
* ext/tcltklib/MANUAL.euc: ditto.
* ext/tk/tkutil.c: fail to create a Tcl's list string from an
array including multiple kind of encoded strings.
* ext/tk/lib/tk.rb: ditto.
* ext/tk/lib/multi-tk.rb: 2nd arg of _{to|from}UTF8 is omissible.
* ext/tk/lib/remote-tk.rb: ditto.
* ext/tk/lib/tk.rb: override TclTkLib#encoding and encoding= to
use TkCore::INTERP.encoding and encoding=.
* ext/tk/lib/tk.rb: when "require 'tk'" and $KCODE=='NONE', check
DEFAULT_TK_ENCODING to decide Ruby/Tk's system encoding mode.
* ext/tk/lib/tk/encodedstr.rb: check both of Tk.encoding and
Tk.encoding_system. Tk.encoding has higher priority.
* ext/tk/lib/tk/optiondb.rb: ditto.
* ext/tk/lib/tk/spinbox.rb: ditto.
* ext/tk/lib/tk/validation.rb: ditto.
* ext/tk/lib/tk/namespace.rb: arguemnts for TclTkIp#_merge_tklist
should be UTF-8 strings.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib')
-rw-r--r-- | ext/tk/lib/multi-tk.rb | 8 | ||||
-rw-r--r-- | ext/tk/lib/remote-tk.rb | 4 | ||||
-rw-r--r-- | ext/tk/lib/tk.rb | 51 | ||||
-rw-r--r-- | ext/tk/lib/tk/encodedstr.rb | 8 | ||||
-rw-r--r-- | ext/tk/lib/tk/namespace.rb | 12 | ||||
-rw-r--r-- | ext/tk/lib/tk/optiondb.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tk/spinbox.rb | 3 | ||||
-rw-r--r-- | ext/tk/lib/tk/validation.rb | 3 |
8 files changed, 69 insertions, 22 deletions
diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb index 6d048e91b..e8bbf67de 100644 --- a/ext/tk/lib/multi-tk.rb +++ b/ext/tk/lib/multi-tk.rb @@ -1730,11 +1730,11 @@ class << MultiTkIp __getip._invoke_with_enc(*args) end - def _toUTF8(str, encoding) + def _toUTF8(str, encoding=nil) __getip._toUTF8(str, encoding) end - def _fromUTF8(str, encoding) + def _fromUTF8(str, encoding=nil) __getip._fromUTF8(str, encoding) end @@ -2119,11 +2119,11 @@ class MultiTkIp @interp._invoke_with_enc(*args) end - def _toUTF8(str, encoding) + def _toUTF8(str, encoding=nil) @interp._toUTF8(str, encoding) end - def _fromUTF8(str, encoding) + def _fromUTF8(str, encoding=nil) @interp._fromUTF8(str, encoding) end diff --git a/ext/tk/lib/remote-tk.rb b/ext/tk/lib/remote-tk.rb index bb2a2c114..ed7f75b33 100644 --- a/ext/tk/lib/remote-tk.rb +++ b/ext/tk/lib/remote-tk.rb @@ -321,11 +321,11 @@ class RemoteTkIp _appsend(true, false, *args) end - def _toUTF8(str, encoding) + def _toUTF8(str, encoding=nil) @interp._toUTF8(str, encoding) end - def _fromUTF8(str, encoding) + def _fromUTF8(str, encoding=nil) @interp._fromUTF8(str, encoding) end diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 9daee2de5..4267b42a3 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -309,19 +309,48 @@ if USE_TCLs_LIST_FUNCTIONS def array2tk_list(ary, enc=nil) return "" if ary.size == 0 + sys_enc = TkCore::INTERP.encoding + sys_enc = TclTkLib.encoding_system unless sys_enc + + dst_enc = (enc == nil)? sys_enc: enc + dst = ary.collect{|e| if e.kind_of? Array - array2tk_list(e, enc) + s = array2tk_list(e, enc) elsif e.kind_of? Hash tmp_ary = [] #e.each{|k,v| tmp_ary << k << v } e.each{|k,v| tmp_ary << "-#{_get_eval_string(k)}" << v } - array2tk_list(tmp_ary, enc) + s = array2tk_list(tmp_ary, enc) else - _get_eval_string(e, enc) + s = _get_eval_string(e, enc) + end + + if dst_enc != true && dst_enc != false + if (s_enc = s.instance_variable_get(:@encoding)) + s_enc = s_enc.to_s + else + s_enc = sys_enc + end + dst_enc = true if s_enc != dst_enc end + + s } - TkCore::INTERP._merge_tklist(*dst) + + if sys_enc && dst_enc + dst.map!{|s| _toUTF8(s)} + ret = TkCore::INTERP._merge_tklist(*dst) + if dst_enc.kind_of?(String) + ret = _fromUTF8(ret, dst_enc) + ret.instance_variable_set(:@encoding, dst_enc) + else + ret.instance_variable_set(:@encoding, 'utf-8') + end + ret + else + TkCore::INTERP._merge_tklist(*dst) + end end else @@ -2163,6 +2192,15 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK) =end end + module TclTkLib + def self.encoding=(name) + TkCore::INTERP.encoding = name + end + def self.encoding + TkCore::INTERP.encoding + end + end + module Tk module Encoding extend Encoding @@ -2231,6 +2269,9 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK) Tk.encoding = 'utf-8' Tk.encoding_system = 'utf-8' else # NONE + if defined? DEFAULT_TK_ENCODING + Tk.encoding_system = DEFAULT_TK_ENCODING + end begin Tk.encoding = Tk.encoding_system rescue StandardError, NameError @@ -4153,7 +4194,7 @@ end #Tk.freeze module Tk - RELEASE_DATE = '2005-06-24'.freeze + RELEASE_DATE = '2005-07-05'.freeze autoload :AUTO_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable' diff --git a/ext/tk/lib/tk/encodedstr.rb b/ext/tk/lib/tk/encodedstr.rb index aed0e7524..797e514a4 100644 --- a/ext/tk/lib/tk/encodedstr.rb +++ b/ext/tk/lib/tk/encodedstr.rb @@ -67,9 +67,13 @@ module Tk def initialize(str, enc = nil) super(str) + # @encoding = ( enc || + # ((self.class::Encoding)? + # self.class::Encoding : Tk.encoding_system) ) @encoding = ( enc || - ((self.class::Encoding)? - self.class::Encoding : Tk.encoding_system) ) + ((self.class::Encoding)? + self.class::Encoding : + ((Tk.encoding)? Tk.encoding : Tk.encoding_system) ) ) end attr_reader :encoding diff --git a/ext/tk/lib/tk/namespace.rb b/ext/tk/lib/tk/namespace.rb index e0ef7c39d..85a94372b 100644 --- a/ext/tk/lib/tk/namespace.rb +++ b/ext/tk/lib/tk/namespace.rb @@ -115,19 +115,19 @@ class TkNamespace < TkObject # alias __tk_call_with_enc tk_call_with_enc def tk_call(*args) #super('namespace', 'eval', @namespace, *args) - args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''} + args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''} super('namespace', 'eval', @namespace, TkCore::INTERP._merge_tklist(*args)) end def tk_call_without_enc(*args) #super('namespace', 'eval', @namespace, *args) - args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''} + args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''} super('namespace', 'eval', @namespace, TkCore::INTERP._merge_tklist(*args)) end def tk_call_with_enc(*args) #super('namespace', 'eval', @namespace, *args) - args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''} + args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''} super('namespace', 'eval', @namespace, TkCore::INTERP._merge_tklist(*args)) end @@ -159,19 +159,19 @@ class TkNamespace < TkObject alias __tk_call_with_enc tk_call_with_enc def tk_call(*args) #super('namespace', 'eval', @fullname, *args) - args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''} + args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''} super('namespace', 'eval', @fullname, TkCore::INTERP._merge_tklist(*args)) end def tk_call_without_enc(*args) #super('namespace', 'eval', @fullname, *args) - args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''} + args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''} super('namespace', 'eval', @fullname, TkCore::INTERP._merge_tklist(*args)) end def tk_call_with_enc(*args) #super('namespace', 'eval', @fullname, *args) - args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''} + args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''} super('namespace', 'eval', @fullname, TkCore::INTERP._merge_tklist(*args)) end diff --git a/ext/tk/lib/tk/optiondb.rb b/ext/tk/lib/tk/optiondb.rb index fe79de123..a806f3971 100644 --- a/ext/tk/lib/tk/optiondb.rb +++ b/ext/tk/lib/tk/optiondb.rb @@ -44,7 +44,7 @@ module TkOptionDB "can't call 'TkOptionDB.read_entries' on a safe interpreter" end - i_enc = Tk.encoding() + i_enc = ((Tk.encoding)? Tk.encoding : Tk.encoding_system) unless f_enc f_enc = i_enc diff --git a/ext/tk/lib/tk/spinbox.rb b/ext/tk/lib/tk/spinbox.rb index fe50d85e4..ac84e06cb 100644 --- a/ext/tk/lib/tk/spinbox.rb +++ b/ext/tk/lib/tk/spinbox.rb @@ -25,7 +25,8 @@ class TkSpinbox<TkEntry [ ?w, TkComm.method(:window) ], [ ?e, proc{|val| - enc = Tk.encoding + #enc = Tk.encoding + enc = ((Tk.encoding)? Tk.encoding : Tk.encoding_system) if enc Tk.fromUTF8(TkComm::string(val), enc) else diff --git a/ext/tk/lib/tk/validation.rb b/ext/tk/lib/tk/validation.rb index eeb0163ee..6755eef05 100644 --- a/ext/tk/lib/tk/validation.rb +++ b/ext/tk/lib/tk/validation.rb @@ -226,7 +226,8 @@ class TkValidateCommand [ ?w, TkComm.method(:window) ], [ ?e, proc{|val| - enc = Tk.encoding + #enc = Tk.encoding + enc = ((Tk.encoding)? Tk.encoding : Tk.encoding_system) if enc Tk.fromUTF8(TkComm::string(val), enc) else |