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.

64 DECODER PARENT CLASS ANNOYANCE-FILTER §68<br />

virtual void discardLine (void)<br />

{<br />

p = src ⃗ length ( );<br />

}<br />

virtual void reportDecoderDiagnostic(const string s) const;<br />

virtual void reportDecoderDiagnostic(const ostringstream &os ) const;<br />

};<br />

69. Return a character assembled by concatenating the next n bytes in most significant byte to least<br />

significant byte order. If the end of input is encountered, −1 is returned. A multiple byte character<br />

equal to −1 triggers an assertion failure in debug builds.<br />

〈 Class implementations 11 〉 +≡<br />

int MBCSdecoder ::getNextNBytes (const unsigned int n)<br />

{<br />

assert((n ≥ 1) ∧ (n ≤ 4));<br />

}<br />

int v = 0;<br />

for (unsigned int i = 0; i < n; i++) {<br />

int b = getNextEncodedByte ( );<br />

if (b < 0) {<br />

return b;<br />

}<br />

v = (v ≪ 8) | b;<br />

}<br />

assert(v ≠ −1);<br />

return v;<br />

70. If the decoder encounters an error, we usually report it as a parser diagnostic to the parent mail<br />

folder. If there is no such folder (since a decoder can be invoked stand-alone), we report the diagnostic<br />

to standard error if the −−verbose option is specified.<br />

〈 Class implementations 11 〉 +≡<br />

void MBCSdecoder ::reportDecoderDiagnostic(const string s) const<br />

{<br />

if (mf ≠ Λ) {<br />

mf ⃗ reportParserDiagnostic(s);<br />

}<br />

else {<br />

if (verbose ) {<br />

cerr ≪ s ≪ endl ;<br />

}<br />

}<br />

}<br />

void MBCSdecoder ::reportDecoderDiagnostic(const ostringstream &os ) const<br />

{<br />

reportDecoderDiagnostic(os .str ( ));<br />

}

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

Saved successfully!

Ooh no, something went wrong!