1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* bug fix : wrong resource file format (resource.{en,jp})

* add Tk::Encoding.{encoding_convertfrom, encoding_convertto}
* add TkOptionDB.read_with_encoding to read non-utf8 resource file


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2003-07-31 23:04:45 +00:00
parent 75362fbd47
commit bc8b42fc1e
5 changed files with 72 additions and 12 deletions

View file

@ -1155,8 +1155,6 @@ class MultiTkIp
# from tkencoding.rb by ttate@jaist.ac.jp
alias __eval _eval
alias __invoke _invoke
private :__eval
private :__invoke
def encoding
@encoding[0]

View file

@ -1509,8 +1509,6 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
# from tkencoding.rb by ttate@jaist.ac.jp
alias __eval _eval
alias __invoke _invoke
private :__eval
private :__invoke
attr_accessor :encoding
@ -1557,6 +1555,16 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
def encoding_system=(enc)
tk_call('encoding', 'system', enc)
end
def encoding_convertfrom(str, enc=None)
TkCore::INTERP.__invoke('encoding', 'convertfrom', enc, str)
end
alias encoding_convert_from encoding_convertfrom
def encoding_convertto(str, enc=None)
TkCore::INTERP.__invoke('encoding', 'convertto', enc, str)
end
alias encoding_convert_to encoding_convertto
end
extend Encoding
@ -1580,6 +1588,11 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK
else
# dummy methods
class TclTkIp
alias __eval _eval
alias __invoke _invoke
end
module Tk
module Encoding
extend Encoding
@ -1599,6 +1612,16 @@ else
def encoding_system=(enc)
nil
end
def encoding_convertfrom(str, enc=None)
str
end
alias encoding_convert_from encoding_convertfrom
def encoding_convertto(str, enc=None)
str
end
alias encoding_convert_to encoding_convertto
end
extend Encoding
@ -2849,6 +2872,43 @@ module TkOptionDB
end
module_function :add, :clear, :get, :readfile
def read_with_encoding(file, f_enc=nil, pri=None)
i_enc = Tk.encoding()
unless f_enc
f_enc = i_enc
end
cline = ''
open(file, 'r') {|f|
while line = f.gets
cline += line.chomp!
case cline
when /\\$/ # continue
cline.chop!
next
when /^!/ # coment
cline = ''
next
when /^([^:]+):\s(.*)$/
pat = $1
val = $2
p "ResourceDB: #{[pat, val].inspect}" if $DEBUG
pat = TkCore::INTERP._toUTF8(pat, f_enc)
pat = TkCore::INTERP._fromUTF8(pat, i_enc)
val = TkCore::INTERP._toUTF8(val, f_enc)
val = TkCore::INTERP._fromUTF8(val, i_enc)
add(pat, val, pri)
cline = ''
else # unknown --> ignore
cline = ''
next
end
end
}
end
module_function :read_with_encoding
# support procs on the resource database
@@resource_proc_class = Class.new
class << @@resource_proc_class

View file

@ -1,6 +1,6 @@
#
# see Tcl/Tk's "options" manual for "Database Name" and "Database Class"
#
!
! see Tcl/Tk's "options" manual for "Database Name" and "Database Class"
!
*BtnFrame.borderWidth: 5
*BtnFrame.relief: ridge
*BtnFrame.Button.background: wheat

View file

@ -1,6 +1,6 @@
#
# see Tcl/Tk's "options" manual for "Database Name" and "Database Class"
#
!
! see Tcl/Tk's "options" manual for "Database Name" and "Database Class"
!
*BtnFrame.borderWidth: 5
*BtnFrame.relief: ridge
*BtnFrame.Button.background: wheat

View file

@ -10,7 +10,9 @@ require "tk"
if ENV['LANG'] =~ /^ja/
# read Japanese resource
TkOptionDB.readfile(File.expand_path('resource.ja', File.dirname(__FILE__)))
TkOptionDB.read_with_encoding(File.expand_path('resource.ja',
File.dirname(__FILE__)),
'euc-jp')
else
# read English resource
TkOptionDB.readfile(File.expand_path('resource.en', File.dirname(__FILE__)))