Project

General

Profile

Feature #1784 » test_big5-hkscs.rb

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

 
1
# encoding: utf-8
2

    
3
require 'open-uri'
4

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

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

    
13

    
14

    
15
# uao?
16
line = 223
17
s = open('http://www.ptt.cc/bbs/Ruby/M.1249815780.A.32D.html').read
18
puts s.lines.to_a[line].force_encoding('binary').inspect
19
# "\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"
20

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