def inputUTF8(uio)
show = Show.new
processUTF8 = lambda{|firstByte, utf8Size|
bytes = [ firstByte ]
unicode = firstByte & (0b11111111 >> (utf8Size + 1))
(1...utf8Size).each{|i|
nextByte = uio.getc
bytes.push(nextByte)
if !nextByte || (nextByte & 0b11000000) != 0b10000000
show.nonLetter([ firstByte ], $CHAR_PERIOD)
uio.ungets(bytes[1...bytes.size])
bytes = nil
break
end
unicode = (unicode << 6) | (nextByte & 0b00111111)
}
if bytes
if (1 << utf8BitCount(utf8Size - 1)) <= unicode
show.unicodeLetter(bytes, unicode)
else
show.nonLetter([ firstByte ], $CHAR_PERIOD)
uio.ungets(bytes[1...bytes.size])
end
end
}
while true
input_sub_ISO_2022_JP_1(uio, show, :ascii)
byte = uio.getc
break if !byte
bytes = [ byte ]
if byte <= 0x7f
show.unicodeLetter(bytes, byte)
elsif (byte & 0b11100000) == 0b11000000
processUTF8.call(byte, 2)
elsif (byte & 0b11110000) == 0b11100000
processUTF8.call(byte, 3)
elsif (byte & 0b11111000) == 0b11110000
processUTF8.call(byte, 4)
else
show.nonLetter([ byte ], $CHAR_PERIOD)
end
end
show.flush
end