12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

66 BIG5 DECODER ANNOYANCE-FILTER §73<br />

73. Big5 decoder.<br />

This decoder extracts logical characters from byte streams encoded in Big5 encoding. In Big5, bytes<br />

in the range # 00– # 7F are single ASCII characters. Bytes with the # 80 bit set are the first byte of a two<br />

byte character, the second byte of which may have any value.<br />

〈 Class definitions 10 〉 +≡<br />

class Big5 MBCSdecoder : public MBCSdecoder {<br />

public:<br />

virtual string name (void)<br />

{<br />

return "Big5";<br />

}<br />

virtual int getNextDecodedChar (void); /∗ Get next decoded byte ∗/<br />

};<br />

74. Decode the next logical character. We return −1 when the end of the encoded line is encountered.<br />

〈 Class implementations 11 〉 +≡<br />

int Big5 MBCSdecoder ::getNextDecodedChar (void)<br />

{<br />

int c1 = getNextEncodedByte ( );<br />

}<br />

if ((c1 ≥ 0) ∧ ((c1 & # 80) ≠ 0)) {<br />

int c2 = getNextEncodedByte ( );<br />

if (c2 ≡ −1) {<br />

ostringstream os ;<br />

os ≪ name ( ) ≪ "_MBCSdecoder:␣Premature␣end␣of␣line␣in␣two␣byte␣character.";<br />

reportDecoderDiagnostic(os );<br />

return −1;<br />

}<br />

return (c1 ≪ 8) | c2 ;<br />

}<br />

return c1 ;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!