private int readScriptString() throws IOException { int quoteChar = next(); if (quoteChar!='\'' && quoteChar!='"') return MISMATCH; while((numRead - lastMark) < safeReadAheadLimit) { int ch = next(); if (ch==quoteChar) return MATCH; else if (ch=='\\') { ch=next(); } else if (ch<0) { return MISMATCH; } else if (ch=='<') { eatSSI(); } } return MISMATCH; }
private int readName(boolean checkEscaped) throws IOException { StringBuilder builder = (checkEscaped && escapedTags!=null) ? new StringBuilder() : null; int ch = next(); if (builder!=null) builder.append((char)ch); if (!isFirstIdChar(ch)) return MISMATCH; ch = next(); if (builder!=null) builder.append((char)ch); while(isIdChar(ch)) { ch=next(); if (builder!=null) builder.append((char)ch); } if (ch!=-1) { push(ch); } //strip off the trailing > if (builder!=null && escapedTags.contains(builder.substring(0, builder.length() - 1))){ return MISMATCH; } return MATCH; }
private int readEntity() throws IOException { int ch = next(); if (ch=='#') return readNumericEntity(); //read an entity reference // for an entity reference, require the ';' for safety. // otherwise we may try and convert part of some company // names to an entity. "Alpha&Beta Corp" for instance. // // TODO: perhaps I should special case some of the // more common ones like & to make the ';' optional... sb.setLength(0); sb.append((char)ch); for (int i=0; i< safeReadAheadLimit; i++) { ch=next(); if (Character.isLetter(ch)) { sb.append((char)ch); } else { break; } } if (ch==';') { String entity=sb.toString(); Character entityChar = entityTable.get(entity); if (entityChar!=null) { numWhitespace = entity.length() + 1 ; return entityChar.charValue(); } } return MISMATCH; }
private int eatSSI() throws IOException { // at this point, only a "<" was read. // on a mismatch, push back the last char so that if it was // a quote that closes the attribute, it will be re-read and matched. int ch = next(); if (ch!='!') { push(ch); return MISMATCH; } ch=next(); if (ch!='-') { push(ch); return MISMATCH; } ch=next(); if (ch!='-') { push(ch); return MISMATCH; } ch=next(); if (ch!='#') { push(ch); return MISMATCH; } push('#'); push('-'); push('-'); return readComment(false); }