# File hexja, line 1226
def inputUTF16(uio, isLE)
  show = Show.new
  
  if $alignedUTF16              # 2バイト境界に整列している場合
    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                          # 2バイト境界に整列していない場合
    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) || # High Surrogates
          (0xdb80 <= unicode && unicode <= 0xdbff) || # High Private Use Surrogates
          (0xdc00 <= unicode && unicode <= 0xdfff) || # Low Surrogates
          (0xe000 <= unicode && unicode <= 0xf8ff)) && # Private Use Area
          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
      
      # 出力が UTF-8 ならば、日本語文字コードへ変換可能でなければならない
      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