Project

General

Profile

Feature #1784 » test_big5-hkscs.rb

godfat (Lin Jen-Shin), 09/08/2009 11:25 PM

 
# encoding: utf-8

require 'open-uri'

line = 177
s = open('http://www.ptt.cc/bbs/Ruby/M.1242065470.A.AEA.html').read
puts s.lines.to_a[line].force_encoding('binary').inspect
# "\xA1u\xA6\xE6\xC6\xF7\xA1ILoki\xA1I\xA1v\xA1]rocky \xC7\xE9\xC7\xBF\xC7\xA9\xC6\xE3\xA1^\n"

puts s.force_encoding('big5-hkscs').encode('utf-8').lines.to_a[line]
# 「行け!Loki!」(rocky ロッキー)



# uao?
line = 223
s = open('http://www.ptt.cc/bbs/Ruby/M.1249815780.A.32D.html').read
puts s.lines.to_a[line].force_encoding('binary').inspect
# "\xA5\xCD\xA6\xBA\xA5h\x83S\xA1B\xB4\xD7\xC0Y\xB3\xC8\xC0w\xA1B\xA4@\xBDu\x8A\xCA\xAE\xC9\xA1B\xB8\xA8\xB8\xA8\xBDU\xBDU\n"

puts s.force_encoding('big5-hkscs').encode('utf-8').lines.to_a[line]
# test.rb:21:in `encode': "\x83" on Big5-HKSCS (Encoding::InvalidByteSequenceError)
# should be "生死去来、棚頭傀儡、一線断時、落落磊磊"
    (1-1/1)