def inputUTF16(uio, isLE)
show = Show.new
if $alignedUTF16
prev = nil
uio.each_byte{|byte|
if prev == nil
prev = byte
else
bytes = [ prev, byte ]
if isLE
show.unicodeLetter(bytes, (byte << 8) + prev)
else
show.unicodeLetter(bytes, (prev << 8) + byte)
end
prev = nil
end
}
show.nonLetter([ prev ], $CHAR_PERIOD) if prev != nil
else
while true
bytes = [ ]
bytes.push(uio.getc)
break if !bytes[0]
bytes.push(uio.getc)
if !bytes[1]
show.nonLetter([ bytes[0] ], $CHAR_PERIOD)
break;
end
unicode = isLE ? (bytes[0] | (bytes[1] << 8)) :
((bytes[0] << 8) | bytes[1])
utf16bePacked = [ unicode ].pack('n')
if (unicode < 0x20 || unicode == 0x7f ||
(0xd800 <= unicode && unicode <= 0xdb7f) ||
(0xdb80 <= unicode && unicode <= 0xdbff) ||
(0xdc00 <= unicode && unicode <= 0xdfff) ||
(0xe000 <= unicode && unicode <= 0xf8ff)) &&
unicode != $CHAR_RETURN && unicode != $CHAR_NEWLINE
show.nonLetter([ bytes[0] ], $CHAR_PERIOD)
uio.ungetc(bytes[1])
next
end
begin
Iconv.conv($outputCS, 'UTF-16BE', utf16bePacked)
rescue
show.nonLetter([ bytes[0] ], $CHAR_PERIOD)
uio.ungetc(bytes[1])
next
end
if !$isOutputCSUTF8
show.unicodeLetter(bytes, unicode)
next
end
catch (:next) {
[ 'CP932', 'SHIFT_JIS', $iso2022jp1, 'EUC-JP' ].each{|cs|
begin
Iconv.conv(cs, 'UTF-16BE', utf16bePacked)
show.unicodeLetter(bytes, unicode)
throw :next
rescue Iconv::IllegalSequence, Iconv::InvalidCharacter
end
}
show.nonLetter([ bytes[0] ], $CHAR_PERIOD)
uio.ungetc(bytes[1])
}
end
end
show.flush
end