public int decode(PeterO.Support.InputStream stream, IEncodingError error) { if(!endofstream){ endofstream=true; if(error.Equals(TextEncoding.ENCODING_ERROR_REPLACE)) return 0xFFFD; else { int[] data=new int[1]; int o=error.emitDecoderError(data,0,1); return (o==0) ? -1 : data[0]; } } return -1; }
public int decode(PeterO.Support.InputStream stream, IEncodingError error) { if(stream==null)throw new ArgumentException(); while(true){ int c=stream.ReadByte(); if(c<0)return -1; if(c<0x80) return c; else { int cp=indexes[(c)&0x7F]; if(cp!=0)return cp; if(error.Equals(TextEncoding.ENCODING_ERROR_REPLACE)) return 0xFFFD; else { int[] data=new int[1]; int o=error.emitDecoderError(data,0,1); if(o>0)return data[0]; } } } }
public int decode(PeterO.Support.InputStream stream, int[] buffer, int offset, int length, IEncodingError error) { if((stream)==null)throw new ArgumentNullException("stream"); if((error)==null)throw new ArgumentNullException("error"); if((buffer)==null)throw new ArgumentNullException("buffer"); if((offset)<0)throw new ArgumentOutOfRangeException("offset"+" not greater or equal to "+"0"+" ("+Convert.ToString(offset,CultureInfo.InvariantCulture)+")"); if((length)<0)throw new ArgumentOutOfRangeException("length"+" not greater or equal to "+"0"+" ("+Convert.ToString(length,CultureInfo.InvariantCulture)+")"); if((offset+length)>buffer.Length)throw new ArgumentOutOfRangeException("offset+length"+" not less or equal to "+Convert.ToString(buffer.Length,CultureInfo.InvariantCulture)+" ("+Convert.ToString(offset+length,CultureInfo.InvariantCulture)+")"); if(length==0)return 0; int total=0; for(int i=0;i<length;i++){ int c=stream.ReadByte(); if(c<0){ break; } else if(c<0x80){ buffer[offset++]=c; total++; } else { int cp=indexes[(c)&0x7F]; if(cp==0){ if(error.Equals(TextEncoding.ENCODING_ERROR_REPLACE)) { cp=0xFFFD; } else { int[] data=new int[1]; int o=error.emitDecoderError(data,0,1); if(o>0)return data[0]; } } buffer[offset++]=cp; total++; } } return (total==0) ? -1 : total; }
public int decode(PeterO.Support.InputStream stream, IEncodingError error) { if(stream==null) throw new ArgumentException(); while(true){ int b=stream.ReadByte(); if(b<0 && bytesNeeded!=0){ bytesNeeded=0; if(error.Equals(TextEncoding.ENCODING_ERROR_REPLACE)) return 0xFFFD; else { int[] data=new int[1]; int o=error.emitDecoderError(data,0,1); if(o>0)return data[0]; continue; } } else if(b<0) return -1; if(bytesNeeded==0){ if(b<0x80) return b; else if(b>=0xc2 && b<=0xdf){ stream.mark(4); bytesNeeded=1; cp=b-0xc0; } else if(b>=0xe0 && b<=0xef){ stream.mark(4); lower=(b==0xe0) ? 0xa0 : 0x80; upper=(b==0xed) ? 0x9f : 0xbf; bytesNeeded=2; cp=b-0xe0; } else if(b>=0xf0 && b<=0xf4){ stream.mark(4); lower=(b==0xf0) ? 0x90 : 0x80; upper=(b==0xf4) ? 0x8f : 0xbf; bytesNeeded=3; cp=b-0xf0; } else { if(error.Equals(TextEncoding.ENCODING_ERROR_REPLACE)) return 0xFFFD; else { int[] data=new int[1]; int o=error.emitDecoderError(data,0,1); if(o>0)return data[0]; continue; } } cp<<=(6*bytesNeeded); continue; } if(b<lower || b>upper){ cp=bytesNeeded=bytesSeen=0; lower=0x80; upper=0xbf; stream.reset(); // 'Decrease the byte pointer by one.' if(error.Equals(TextEncoding.ENCODING_ERROR_REPLACE)) return 0xFFFD; else { int[] data=new int[1]; int o=error.emitDecoderError(data,0,1); if(o>0)return data[0]; continue; } } lower=0x80; upper=0xbf; bytesSeen++; cp+=(b-0x80)<<(6*(bytesNeeded-bytesSeen)); stream.mark(4); if(bytesSeen!=bytesNeeded) { continue; } int ret=cp; cp=0; bytesSeen=0; bytesNeeded=0; return ret; } }