/** * Skips the remainder of a comment. It is assumed that <!- is already read. * * @param reader the reader * @throws java.io.IOException if an error occurred reading the data */ static void skipComment(IXMLReader reader) throws IOException, XMLParseException { if (reader.read() != '-') { XMLUtil.errorExpectedInput(reader.getSystemID(), reader.getLineNr(), "<!--"); } int dashesRead = 0; for (; ; ) { char ch = reader.read(); switch (ch) { case '-': dashesRead++; break; case '>': if (dashesRead == 2) { return; } dashesRead = 0; break; default: dashesRead = 0; } } }
/** * Retrieves a delimited string from the data. * * @param reader the reader * @param entityChar the escape character (& or %) * @param entityResolver the entity resolver * @throws java.io.IOException if an error occurred reading the data */ static String scanString(IXMLReader reader, char entityChar, IXMLEntityResolver entityResolver) throws IOException, XMLParseException { StringBuffer result = new StringBuffer(); int startingLevel = reader.getStreamLevel(); char delim = reader.read(); if ((delim != '\'') && (delim != '"')) { XMLUtil.errorExpectedInput(reader.getSystemID(), reader.getLineNr(), "delimited string"); } for (; ; ) { String str = XMLUtil.read(reader, entityChar); char ch = str.charAt(0); if (ch == entityChar) { if (str.charAt(1) == '#') { result.append(XMLUtil.processCharLiteral(str)); } else { XMLUtil.processEntity(str, reader, entityResolver); } } else if (ch == '&') { reader.unread(ch); str = XMLUtil.read(reader, '&'); if (str.charAt(1) == '#') { result.append(XMLUtil.processCharLiteral(str)); } else { result.append(str); } } else if (reader.getStreamLevel() == startingLevel) { if (ch == delim) { break; } else if ((ch == 9) || (ch == 10) || (ch == 13)) { result.append(' '); } else { result.append(ch); } } else { result.append(ch); } } return result.toString(); }