2 * content builder for Shift_JIS
4 * License : The MIT License
5 * Copyright(c) 2009 olyutorskii
8 package jp.sourceforge.jindolf.parser;
11 * "Shift_JIS"エンコーディング用デコードハンドラ。
12 * {@link SjisDecoder}からの通知に従い、
13 * {@link DecodedContent}へとデコードする。
15 public class ContentBuilderSJ extends ContentBuilder{
17 private static final int DEF_BUF_SZ = 128;
20 private boolean hasByte1st;
26 * 長さ0で空の{@link DecodedContent}がセットされる。
28 public ContentBuilderSJ(){
35 * 長さ0で空の{@link DecodedContent}がセットされる。
36 * @param capacity 初期容量
37 * @throws NegativeArraySizeException 容量指定が負。
39 public ContentBuilderSJ(int capacity) throws NegativeArraySizeException{
48 private void initImpl(){
50 this.hasByte1st = false;
59 protected void init(){
68 protected void flushError(){
70 getContent().addDecodeError(this.byte1st);
71 this.hasByte1st = false;
78 * @param seq {@inheritDoc}
79 * @throws DecodeException {@inheritDoc}
82 public void charContent(CharSequence seq)
83 throws DecodeException{
85 getContent().append(seq);
91 * @param errorArray {@inheritDoc}
92 * @param offset {@inheritDoc}
93 * @param length {@inheritDoc}
94 * @throws DecodeException {@inheritDoc}
97 public void decodingError(byte[] errorArray, int offset, int length)
98 throws DecodeException{
99 int limit = offset + length;
100 for(int bpos = offset; bpos < limit; bpos++){
101 byte bval = errorArray[bpos];
104 if(ShiftJis.isShiftJIS2ndByte(bval)){ // 文字集合エラー
105 getContent().addDecodeError(this.byte1st, bval);
106 this.hasByte1st = false;
107 }else if(ShiftJis.isShiftJIS1stByte(bval)){
108 getContent().addDecodeError(this.byte1st);
110 this.hasByte1st = true;
112 getContent().addDecodeError(this.byte1st);
113 getContent().addDecodeError(bval);
114 this.hasByte1st = false;
117 if(ShiftJis.isShiftJIS1stByte(bval)){
119 this.hasByte1st = true;
121 getContent().addDecodeError(bval);