2 * Shift_JIS encoding utilities
4 * License : The MIT License
5 * Copyright(c) 2009 olyutorskii
8 package jp.sourceforge.jindolf.parser;
10 import java.nio.charset.Charset;
14 * JIS X0208:1997 準拠。(Windows-31Jではない!)
15 * @see <a href="http://www.iana.org/assignments/character-sets">
17 * @see <a href="http://ja.wikipedia.org/wiki/Shift_JIS">
18 * Wikipedia: Shift_JIS</a>
20 public final class ShiftJis{
23 public static final String ENCODE_NAME = "Shift_JIS";
24 /** SHift_JIS用Charsetインスタンス。 */
25 public static final Charset CHARSET = Charset.forName(ENCODE_NAME);
26 /** char1文字をエンコードした時の最大バイト数。 */
27 public static final int MAX_BYTES_PER_CHAR = 2;
40 * 任意のバイト値がシフトJISの1バイト目でありうるか否か判定する。
43 * @return シフトJISの1バイト目でありうるならtrue
45 public static boolean isShiftJIS1stByte(byte bval){
46 if( (byte)0x81 <= bval && bval <= (byte)0x9f
47 || (byte)0xe0 <= bval && bval <= (byte)0xfc){
54 * 任意のバイト値がシフトJISの2バイト目でありうるか否か判定する。
57 * @return シフトJISの2バイト目でありうるならtrue
59 public static boolean isShiftJIS2ndByte(byte bval){
60 if( (byte)0x40 <= bval && bval <= (byte)0x7e
61 || (byte)0x80 <= bval && bval <= (byte)0xfc){
68 * 任意のバイト値ペアがシフトJISでありうるか否か判定する。
72 * @return シフトJISならtrue
74 public static boolean isShiftJIS(byte b1st, byte b2nd){
75 if( ShiftJis.isShiftJIS1stByte(b1st)
76 && ShiftJis.isShiftJIS2ndByte(b2nd)){