12.06.2015 Views

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

The Annoyance Filter.pdf - Fourmilab

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

76 INTERPRETER PARENT CLASS ANNOYANCE-FILTER §89<br />

89. We provide this default implementation of getNextDecodedChar for derived classes. <strong>The</strong>y’re free<br />

to override it, but this may do the job for most. A logical character is obtained from the decoder.<br />

If its character code is less than or equal to 256, it is taken as a single byte character and returned<br />

directly. Otherwise, a character name is concocted by concatenating the character set name and the<br />

hexadecimal character code, with the prefix and suffix at either end. Character sets in which each<br />

ideograph is logically a word will typically use a prefix and suffix of a single blank, while sets in which<br />

characters behave like letters will use a void prefix and suffix.<br />

〈 Class implementations 11 〉 +≡<br />

string MBCSinterpreter ::getNextDecodedChar (void)<br />

{<br />

assert(dp ≠ Λ);<br />

}<br />

int dc = dp ⃗ getNextDecodedChar ( );<br />

if (dc < 0) {<br />

return ""; /∗ End of input stream ∗/<br />

}<br />

if (dc < 256) {<br />

string r(1, static cast〈char〉(dc));<br />

}<br />

return r;<br />

ostringstream os ;<br />

os .setf (ios ::uppercase );<br />

os ≪ prefix ≪ name ( ) ≪ "−" ≪ hex ≪ dc ≪ dec ≪ suffix ;<br />

return os .str ( );<br />

90. <strong>The</strong> default implementation of decodeLine sets the source to the argument string, then assembles<br />

a line by concatenating the results of successive calls to getNextDecodedChar .<br />

〈 Class implementations 11 〉 +≡<br />

string MBCSinterpreter ::decodeLine (const string &s)<br />

{<br />

string r = "", t;<br />

}<br />

setSource (s);<br />

while ((t = getNextDecodedChar ( )) ≠ "") {<br />

r += t;<br />

}<br />

return r;

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

Saved successfully!

Ooh no, something went wrong!