2 * Shift_JIS encoding utilities
4 * License : The MIT License
5 * Copyright(c) 2009 olyutorskii
8 package jp.osdn.jindolf.parser.content;
10 import java.nio.charset.Charset;
15 * <p>JIS X0208:1997 準拠。(Windows-31Jではない!)
17 * @see <a href="http://www.iana.org/assignments/character-sets">
19 * @see <a href="http://ja.wikipedia.org/wiki/Shift_JIS">
20 * Wikipedia: Shift_JIS</a>
22 public final class ShiftJis{
25 public static final String ENCODE_NAME = "Shift_JIS";
26 /** SHift_JIS用Charsetインスタンス。 */
27 public static final Charset CHARSET = Charset.forName(ENCODE_NAME);
28 /** char1文字をエンコードした時の最大バイト数。 */
29 public static final int MAX_BYTES_PER_CHAR = 2;
42 * 任意のバイト値がシフトJISの1バイト目でありうるか否か判定する。
46 * @return シフトJISの1バイト目でありうるならtrue
48 public static boolean isShiftJIS1stByte(byte bval){
49 int iVal = (int) bval & 0xff;
51 0x81 <= iVal && iVal <= 0x9f
52 || 0xe0 <= iVal && iVal <= 0xfc;
57 * 任意のバイト値がシフトJISの2バイト目でありうるか否か判定する。
61 * @return シフトJISの2バイト目でありうるならtrue
63 public static boolean isShiftJIS2ndByte(byte bval){
64 int iVal = (int) bval & 0xff;
66 0x40 <= iVal && iVal <= 0x7e
67 || 0x80 <= iVal && iVal <= 0xfc;
72 * 任意のバイト値ペアがシフトJISでありうるか否か判定する。
77 * @return シフトJISならtrue
79 public static boolean isShiftJIS(byte b1st, byte b2nd){
81 ShiftJis.isShiftJIS1stByte(b1st)
82 && ShiftJis.isShiftJIS2ndByte(b2nd);