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.

§50 ANNOYANCE-FILTER BASE64 MIME DECODER 51<br />

50. This is the heart of the base64 decoder. It reads the next four significant (non-white space)<br />

characters from the input stream, extracts the 6 bits encoded by each, and assembles the bits into<br />

three 8 bit bytes which are added to the decodedBytes queue. Although the current decoder always<br />

immediately empties the queue, in principal any sequence of the encoded content up to its entire length<br />

may be decoded by repeated invocations of this code.<br />

〈 Refill decoded bytes queue from input stream 50 〉 ≡<br />

unsigned char a[4], b[4], o[3];<br />

int j, k;<br />

〈 Decode next four characters from input stream 51 〉;<br />

〈 Assemble the decoded bits into bytes and place on decoded queue 54 〉;<br />

This code is used in section 49.<br />

51. Read the next four non-blank bytes from the input stream, checking for end of file, and place<br />

their decoded 6 bit values into the array b. We save the original encoded characters in array a to permit<br />

testing them for the special “=” sentinel which denotes short sequences at the end of file.<br />

〈 Decode next four characters from input stream 51 〉 ≡<br />

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

int c;<br />

}<br />

〈 Get next significant character from input stream 52 〉;<br />

〈 Check for end of file in base64 stream 53 〉;<br />

if (dtable [c] & # 80) {<br />

nDecodeErrors ++;<br />

ostringstream os ;<br />

os ≪ "Illegal␣character␣’" ≪ c ≪ "’␣in␣Base64␣input␣stream.";<br />

mf ⃗ reportParserDiagnostic(os .str ( )); /∗ Ignoring errors: discard invalid character. ∗/<br />

i−−;<br />

continue;<br />

}<br />

a[i] = (unsigned char) c;<br />

b[i] = dtable [c];<br />

This code is used in section 50.

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

Saved successfully!

Ooh no, something went wrong!