Improves search of EI (end of inlined image)

This commit is contained in:
Yury Delendik 2013-06-21 17:03:03 -05:00
parent ce218d021f
commit c68d125f17
4 changed files with 30 additions and 1 deletions

View file

@ -154,13 +154,22 @@ var Parser = (function ParserClosure() {
var startPos = stream.pos;
// searching for the /EI\s/
var state = 0, ch;
var state = 0, ch, i, ii;
while (state != 4 &&
(ch = stream.getByte()) !== null && ch !== undefined) {
switch (ch) {
case 0x20:
case 0x0D:
case 0x0A:
// let's check next five bytes to be ASCII... just be sure
var followingBytes = stream.peekBytes(5);
for (i = 0, ii = followingBytes.length; i < ii; i++) {
ch = followingBytes[i];
if (ch !== 0x0A && ch != 0x0D && (ch < 0x20 || ch > 0x7F)) {
state = 0;
break; // some binary stuff found, resetting the state
}
}
state = state === 3 ? 4 : 0;
break;
case 0x45: