[ruby-core:18774] ã« Michael Selig ã‹ã‚‰ Encoding::default_internal
ã®æ案ãŒã‚ã‚Šã¾ã—ãŸã€‚
http://redmine.ruby-lang.org/wiki/ruby/DevelopersMeeting20080922
ã«è¿½åŠ ã—ãŸã‚‰
Encoding::default_internal (Michael Selig, ruby-core:18774)
çµæžœã¯
→ pending (今週ä¸)
ã¨ãªã‚Šã¾ã—ãŸã€‚ã“ã®ä»¶ã‚’勧ã‚ã‚‹ãŸã‚ã«ãƒ‘ッãƒã‚’作りã¾ã—ãŸã€‚
よã‹ã£ãŸã‚‰å…¥ã‚Œã¦ãŠãã¾ã™ãŒã€ç”°ä¸ã•ã‚“ã€æˆç€¬ã•ã‚“ã‚ãŸã‚ŠãŒ
ãã£ã¨ã‚‚ã£ã¨ã„ã„ã‚‚ã®ã‚’作れるã®ã§ã“ã¡ã‚‰ã®ãƒ‘ッãƒã‚’使ã‚ãªãã¦ã‚‚
ã„ã„ã§ã™ã€‚
テストã¯æœªã åˆæœŸæ®µéšŽã§ã™ãŒã€ã¨ã‚Šã‚ãˆãšæ¬¡ã®ã‚ˆã†ã«ãƒ†ã‚¹ãƒˆã—ã¾ã—ãŸ
(実行㯠-Eutf-8, -Eshift_jis, -Eeuc-jp, ãã—㦠-E ç„¡ã—ã§ã€
ãã‚Œãžã‚Œã®å ´åˆ default_internal ã®å€¤ã‚’色々変更ã—ã¾ã—ãŸ
(åˆã‚ã›ã¦æœ€å¾Œã®è¡Œã®ãƒ•ã‚¡ã‚¤ãƒ«ç•ªèªžã‚‚変更ã—ãªã„ã¨ã„ã‘ã¾ã›ã‚“))
Encoding.default_internal = ‘utf-8’
# tested with ‘utf-8’, ‘shift_jis’, and ‘euc-jp’
s = “\u3042\u3044\u3046\u3048\u304A”
File.open(‘testout1.txt’, ‘w:shift_jis’) do |f| f.write s end
File.open(‘testout2.txt’, ‘w:euc-jp’) do |f| f.write s end
File.open(‘testout3.txt’, ‘w:utf-8’) do |f| f.write s end
File.open(‘testout1.txt’, ‘r:shift_jis’) do |f| s = f.read; p s.encoding
end
File.open(‘testout2.txt’, ‘r:euc-jp’) do |f| s = f.read; p s.encoding
end
File.open(‘testout3.txt’, ‘r:utf-8’) do |f| s = f.read; p s.encoding end
File.open(‘testout3.txt’, ‘r:ASCII-8BIT’) do |f| s = f.read; p
s.encoding end
for next line, change file number to pick up default_internal
File.open(‘testout3.txt’, ‘r’) do |f| s = f.read; p s.encoding end
是éžã¨ã‚‚宜ã—ããŠé¡˜ã„ã—ã¾ã™ã€‚ Martin.
#-#-# Martin J. Du"rst, Assoc. Professor, Aoyama Gakuin University
#-#-# http://www.sw.it.aoyama.ac.jp mailto:[email protected]