2 * content builder for Shift_JIS
\r
4 * License : The MIT License
\r
5 * Copyright(c) 2009 olyutorskii
\r
8 package jp.sourceforge.jindolf.parser;
\r
11 * "Shift_JIS"エンコーディング用デコードハンドラ。
\r
12 * {@link SjisDecoder}からの通知に従い、
\r
13 * {@link DecodedContent}へとデコードする。
\r
15 public class ContentBuilderSJ extends ContentBuilder{
\r
17 private boolean hasByte1st;
\r
18 private byte byte1st;
\r
22 * 長さ0で空の{@link DecodedContent}がセットされる。
\r
24 public ContentBuilderSJ(){
\r
31 * 長さ0で空の{@link DecodedContent}がセットされる。
\r
32 * @param capacity 初期容量
\r
33 * @throws NegativeArraySizeException 容量指定が負。
\r
35 public ContentBuilderSJ(int capacity) throws NegativeArraySizeException{
\r
44 private void initImpl(){
\r
45 this.content.init();
\r
46 this.hasByte1st = false;
\r
47 this.byte1st = 0x00;
\r
55 protected void init(){
\r
64 protected void flushError(){
\r
65 if(this.hasByte1st){
\r
66 this.content.addDecodeError(this.byte1st);
\r
67 this.hasByte1st = false;
\r
74 * @param seq {@inheritDoc}
\r
75 * @throws DecodeException {@inheritDoc}
\r
77 public void charContent(CharSequence seq)
\r
78 throws DecodeException{
\r
80 this.content.append(seq);
\r
86 * @param errorArray {@inheritDoc}
\r
87 * @param offset {@inheritDoc}
\r
88 * @param length {@inheritDoc}
\r
89 * @throws DecodeException {@inheritDoc}
\r
91 public void decodingError(byte[] errorArray, int offset, int length)
\r
92 throws DecodeException{
\r
93 int limit = offset + length;
\r
94 for(int bpos = offset; bpos < limit; bpos++){
\r
95 byte bval = errorArray[bpos];
\r
96 if( ! this.hasByte1st){
\r
97 if(ShiftJis.isShiftJIS1stByte(bval)){
\r
98 this.byte1st = bval;
\r
99 this.hasByte1st = true;
\r
101 this.content.addDecodeError(bval);
\r
104 if(ShiftJis.isShiftJIS2ndByte(bval)){ // 文字集合エラー
\r
105 this.content.addDecodeError(this.byte1st, bval);
\r
106 this.hasByte1st = false;
\r
107 }else if(ShiftJis.isShiftJIS1stByte(bval)){
\r
108 this.content.addDecodeError(this.byte1st);
\r
109 this.byte1st = bval;
\r
110 this.hasByte1st = true;
\r
112 this.content.addDecodeError(this.byte1st);
\r
113 this.content.addDecodeError(bval);
\r
114 this.hasByte1st = false;
\r