LoginSignup
7
5

More than 5 years have passed since last update.

Java で Shift_JIS を Unicode へ変換する際の非互換

Posted at

(久しぶりに嵌ったので、忘れないうちにメモ)

3 種類の変換テーブル

Java には、Shift_JIS を Unicode へ変換するテーブルが 3 種類ある。

  • Shift_JIS
  • windows-31j
  • x-IBM943

一部の文字('~'など)に対して、それぞれのテーブルが独自の変換をし異なる Unicode へ変換する。このため、Shift_JIS の文字化けの原因となる。
なお、これらの変換テーブルは Charset クラスの forName メソッドを用い次のようにして取得することができる。

Charset charset = Charset.forName("windows-31j");

Shift_JIS 変換の非互換

どのような文字に非互換があるかを次表に示す。

Glyph Shift_JIS Code "Shift_JIS"によるUnicodeへの変換 "windows-31j"によるUnicodeへの変換 "x-IBM943"によるUnicodeへの変換
\ 5c 5c 5c a5
~ 7e 7e 7e 203e
815c 2014 2015 2014
8160 301c ff5e 301c
8161 2016 2225 2016
817c 2212 ff0d 2212
8191 a2 ffe0 ffe0
8192 a3 ffe1 ffe1
81ca ac ffe2 ffe2
eefa n/a ffe4 a6
fa55 n/a ffe4 a6

表中に n/a とあるのは、Shift_JIS は、機種依存文字や全角ハイフンを変換できないためである。
なお、Shift_JISwindows-31j では、変換できない場合、変換できない文字が fffd になる。
x-IBM943 では、変換できない文字は 0 となるようである。

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5