Remove HTML5 parser java docs and generation code.

master
Fedor 2019-09-20 13:11:30 +03:00
parent 4b21081b0d
commit 3ebbfc6e8f
34 changed files with 0 additions and 20210 deletions

View File

@ -1,59 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
libs:: translator
translator:: javaparser \
; mkdir -p htmlparser/bin && \
find htmlparser/translator-src/nu/validator/htmlparser -name "*.java" | \
xargs javac -cp javaparser.jar -g -d htmlparser/bin && \
jar cfm translator.jar manifest.txt -C htmlparser/bin .
javaparser:: \
; mkdir -p javaparser/bin && \
find javaparser/src -name "*.java" | \
xargs javac -encoding ISO-8859-1 -g -d javaparser/bin && \
jar cf javaparser.jar -C javaparser/bin .
sync_javaparser:: \
; if [ ! -d javaparser/.git ] ; \
then rm -rf javaparser ; \
git clone https://github.com/javaparser/javaparser.git ; \
fi ; \
cd javaparser ; git checkout javaparser-1.0.6 ; cd ..
sync_htmlparser:: \
; if [ -d htmlparser/.hg ] ; \
then cd htmlparser ; hg pull --rebase ; cd .. ; \
else \
rm -rf htmlparser ; \
hg clone https://hg.mozilla.org/projects/htmlparser ; \
fi
sync:: sync_javaparser sync_htmlparser
translate:: translator \
; mkdir -p ../javasrc ; \
java -jar translator.jar \
htmlparser/src/nu/validator/htmlparser/impl \
.. ../nsHtml5AtomList.h
translate_from_snapshot:: translator \
; mkdir -p ../javasrc ; \
java -jar translator.jar \
../javasrc \
.. ../nsHtml5AtomList.h
named_characters:: translator \
; java -cp translator.jar \
nu.validator.htmlparser.generator.GenerateNamedCharactersCpp \
named-character-references.html ../
clean_javaparser:: \
; rm -rf javaparser/bin javaparser.jar
clean_htmlparser:: \
; rm -rf htmlparser/bin translator.jar
clean:: clean_javaparser clean_htmlparser

View File

@ -1,46 +0,0 @@
If this is your first time building the HTML5 parser, you need to execute the
following commands (from this directory) to bootstrap the translation:
make sync # fetch remote source files and licenses
make translate # perform the Java-to-C++ translation from the remote
# sources
make named_characters # Generate tables for named character tokenization
If you make changes to the translator or the javaparser, you can rebuild by
retyping 'make' in this directory. If you make changes to the HTML5 Java
implementation, you can retranslate the Java sources from the htmlparser
repository by retyping 'make translate' in this directory.
The makefile supports the following targets:
sync_htmlparser:
Retrieves the HTML parser and Java to C++ translator sources from Mozilla's
htmlparser repository.
sync_javaparser:
Retrieves the javaparser sources from GitHub.
sync:
Runs both sync_javaparser and sync_htmlparser.
javaparser:
Builds the javaparser library retrieved earlier by sync_javaparser.
translator:
Runs the javaparser target and then builds the Java to C++ translator from
sources retrieved earlier by sync_htmlparser.
libs:
The default target. Alias for translator
translate:
Runs the translator target and then translates the HTML parser sources
retrieved by sync_htmlparser copying the Java sources to ../javasrc.
translate_from_snapshot:
Runs the translator target and then translates the HTML parser sources
stored in ../javasrc.
named_characters:
Generates data tables for named character tokenization.
clean_javaparser:
Removes the build products of the javaparser target.
clean_htmlparser:
Removes the build products of the translator target.
clean:
Runs both clean_javaparser and clean_htmlparser.
Ben Newman (23 September 2009)
Henri Sivonen (11 August 2016)

View File

@ -1,2 +0,0 @@
Main-Class: nu.validator.htmlparser.cpptranslate.Main
Class-Path: javaparser.jar

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,618 +0,0 @@
/*
* Copyright (c) 2007 Henri Sivonen
* Copyright (c) 2008-2011 Mozilla Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package nu.validator.htmlparser.impl;
import nu.validator.htmlparser.annotation.Auto;
import nu.validator.htmlparser.annotation.IdType;
import nu.validator.htmlparser.annotation.Local;
import nu.validator.htmlparser.annotation.NsUri;
import nu.validator.htmlparser.annotation.Prefix;
import nu.validator.htmlparser.annotation.QName;
import nu.validator.htmlparser.common.Interner;
import nu.validator.htmlparser.common.XmlViolationPolicy;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* Be careful with this class. QName is the name in from HTML tokenization.
* Otherwise, please refer to the interface doc.
*
* @version $Id: AttributesImpl.java 206 2008-03-20 14:09:29Z hsivonen $
* @author hsivonen
*/
public final class HtmlAttributes implements Attributes {
// [NOCPP[
private static final AttributeName[] EMPTY_ATTRIBUTENAMES = new AttributeName[0];
private static final String[] EMPTY_STRINGS = new String[0];
// ]NOCPP]
public static final HtmlAttributes EMPTY_ATTRIBUTES = new HtmlAttributes(
AttributeName.HTML);
private int mode;
private int length;
private @Auto AttributeName[] names;
private @Auto String[] values; // XXX perhaps make this @NoLength?
// CPPONLY: private @Auto int[] lines; // XXX perhaps make this @NoLength?
// [NOCPP[
private String idValue;
private int xmlnsLength;
private AttributeName[] xmlnsNames;
private String[] xmlnsValues;
// ]NOCPP]
public HtmlAttributes(int mode) {
this.mode = mode;
this.length = 0;
/*
* The length of 5 covers covers 98.3% of elements
* according to Hixie, but lets round to the next power of two for
* jemalloc.
*/
this.names = new AttributeName[8];
this.values = new String[8];
// CPPONLY: this.lines = new int[8];
// [NOCPP[
this.idValue = null;
this.xmlnsLength = 0;
this.xmlnsNames = HtmlAttributes.EMPTY_ATTRIBUTENAMES;
this.xmlnsValues = HtmlAttributes.EMPTY_STRINGS;
// ]NOCPP]
}
/*
public HtmlAttributes(HtmlAttributes other) {
this.mode = other.mode;
this.length = other.length;
this.names = new AttributeName[other.length];
this.values = new String[other.length];
// [NOCPP[
this.idValue = other.idValue;
this.xmlnsLength = other.xmlnsLength;
this.xmlnsNames = new AttributeName[other.xmlnsLength];
this.xmlnsValues = new String[other.xmlnsLength];
// ]NOCPP]
}
*/
void destructor() {
clear(0);
}
/**
* Only use with a static argument
*
* @param name
* @return
*/
public int getIndex(AttributeName name) {
for (int i = 0; i < length; i++) {
if (names[i] == name) {
return i;
}
}
return -1;
}
/**
* Only use with static argument.
*
* @see org.xml.sax.Attributes#getValue(java.lang.String)
*/
public String getValue(AttributeName name) {
int index = getIndex(name);
if (index == -1) {
return null;
} else {
return getValueNoBoundsCheck(index);
}
}
public int getLength() {
return length;
}
/**
* Variant of <code>getLocalName(int index)</code> without bounds check.
* @param index a valid attribute index
* @return the local name at index
*/
public @Local String getLocalNameNoBoundsCheck(int index) {
// CPPONLY: assert index < length && index >= 0: "Index out of bounds";
return names[index].getLocal(mode);
}
/**
* Variant of <code>getURI(int index)</code> without bounds check.
* @param index a valid attribute index
* @return the namespace URI at index
*/
public @NsUri String getURINoBoundsCheck(int index) {
// CPPONLY: assert index < length && index >= 0: "Index out of bounds";
return names[index].getUri(mode);
}
/**
* Variant of <code>getPrefix(int index)</code> without bounds check.
* @param index a valid attribute index
* @return the namespace prefix at index
*/
public @Prefix String getPrefixNoBoundsCheck(int index) {
// CPPONLY: assert index < length && index >= 0: "Index out of bounds";
return names[index].getPrefix(mode);
}
/**
* Variant of <code>getValue(int index)</code> without bounds check.
* @param index a valid attribute index
* @return the attribute value at index
*/
public String getValueNoBoundsCheck(int index) {
// CPPONLY: assert index < length && index >= 0: "Index out of bounds";
return values[index];
}
/**
* Variant of <code>getAttributeName(int index)</code> without bounds check.
* @param index a valid attribute index
* @return the attribute name at index
*/
public AttributeName getAttributeNameNoBoundsCheck(int index) {
// CPPONLY: assert index < length && index >= 0: "Index out of bounds";
return names[index];
}
// CPPONLY: /**
// CPPONLY: * Obtains a line number without bounds check.
// CPPONLY: * @param index a valid attribute index
// CPPONLY: * @return the line number at index or -1 if unknown
// CPPONLY: */
// CPPONLY: public int getLineNoBoundsCheck(int index) {
// CPPONLY: assert index < length && index >= 0: "Index out of bounds";
// CPPONLY: return lines[index];
// CPPONLY: }
// [NOCPP[
/**
* Variant of <code>getQName(int index)</code> without bounds check.
* @param index a valid attribute index
* @return the QName at index
*/
public @QName String getQNameNoBoundsCheck(int index) {
return names[index].getQName(mode);
}
/**
* Variant of <code>getType(int index)</code> without bounds check.
* @param index a valid attribute index
* @return the attribute type at index
*/
public @IdType String getTypeNoBoundsCheck(int index) {
return (names[index] == AttributeName.ID) ? "ID" : "CDATA";
}
public int getIndex(String qName) {
for (int i = 0; i < length; i++) {
if (names[i].getQName(mode).equals(qName)) {
return i;
}
}
return -1;
}
public int getIndex(String uri, String localName) {
for (int i = 0; i < length; i++) {
if (names[i].getLocal(mode).equals(localName)
&& names[i].getUri(mode).equals(uri)) {
return i;
}
}
return -1;
}
public @IdType String getType(String qName) {
int index = getIndex(qName);
if (index == -1) {
return null;
} else {
return getType(index);
}
}
public @IdType String getType(String uri, String localName) {
int index = getIndex(uri, localName);
if (index == -1) {
return null;
} else {
return getType(index);
}
}
public String getValue(String qName) {
int index = getIndex(qName);
if (index == -1) {
return null;
} else {
return getValue(index);
}
}
public String getValue(String uri, String localName) {
int index = getIndex(uri, localName);
if (index == -1) {
return null;
} else {
return getValue(index);
}
}
public @Local String getLocalName(int index) {
if (index < length && index >= 0) {
return names[index].getLocal(mode);
} else {
return null;
}
}
public @QName String getQName(int index) {
if (index < length && index >= 0) {
return names[index].getQName(mode);
} else {
return null;
}
}
public @IdType String getType(int index) {
if (index < length && index >= 0) {
return (names[index] == AttributeName.ID) ? "ID" : "CDATA";
} else {
return null;
}
}
public AttributeName getAttributeName(int index) {
if (index < length && index >= 0) {
return names[index];
} else {
return null;
}
}
public @NsUri String getURI(int index) {
if (index < length && index >= 0) {
return names[index].getUri(mode);
} else {
return null;
}
}
public @Prefix String getPrefix(int index) {
if (index < length && index >= 0) {
return names[index].getPrefix(mode);
} else {
return null;
}
}
public String getValue(int index) {
if (index < length && index >= 0) {
return values[index];
} else {
return null;
}
}
public String getId() {
return idValue;
}
public int getXmlnsLength() {
return xmlnsLength;
}
public @Local String getXmlnsLocalName(int index) {
if (index < xmlnsLength && index >= 0) {
return xmlnsNames[index].getLocal(mode);
} else {
return null;
}
}
public @NsUri String getXmlnsURI(int index) {
if (index < xmlnsLength && index >= 0) {
return xmlnsNames[index].getUri(mode);
} else {
return null;
}
}
public String getXmlnsValue(int index) {
if (index < xmlnsLength && index >= 0) {
return xmlnsValues[index];
} else {
return null;
}
}
public int getXmlnsIndex(AttributeName name) {
for (int i = 0; i < xmlnsLength; i++) {
if (xmlnsNames[i] == name) {
return i;
}
}
return -1;
}
public String getXmlnsValue(AttributeName name) {
int index = getXmlnsIndex(name);
if (index == -1) {
return null;
} else {
return getXmlnsValue(index);
}
}
public AttributeName getXmlnsAttributeName(int index) {
if (index < xmlnsLength && index >= 0) {
return xmlnsNames[index];
} else {
return null;
}
}
// ]NOCPP]
void addAttribute(AttributeName name, String value
// [NOCPP[
, XmlViolationPolicy xmlnsPolicy
// ]NOCPP]
// CPPONLY: , int line
) throws SAXException {
// [NOCPP[
if (name == AttributeName.ID) {
idValue = value;
}
if (name.isXmlns()) {
if (xmlnsNames.length == xmlnsLength) {
int newLen = xmlnsLength == 0 ? 2 : xmlnsLength << 1;
AttributeName[] newNames = new AttributeName[newLen];
System.arraycopy(xmlnsNames, 0, newNames, 0, xmlnsNames.length);
xmlnsNames = newNames;
String[] newValues = new String[newLen];
System.arraycopy(xmlnsValues, 0, newValues, 0, xmlnsValues.length);
xmlnsValues = newValues;
}
xmlnsNames[xmlnsLength] = name;
xmlnsValues[xmlnsLength] = value;
xmlnsLength++;
switch (xmlnsPolicy) {
case FATAL:
// this is ugly
throw new SAXException("Saw an xmlns attribute.");
case ALTER_INFOSET:
return;
case ALLOW:
// fall through
}
}
// ]NOCPP]
if (names.length == length) {
int newLen = length << 1; // The first growth covers virtually
// 100% of elements according to
// Hixie
AttributeName[] newNames = new AttributeName[newLen];
System.arraycopy(names, 0, newNames, 0, names.length);
names = newNames;
String[] newValues = new String[newLen];
System.arraycopy(values, 0, newValues, 0, values.length);
values = newValues;
// CPPONLY: int[] newLines = new int[newLen];
// CPPONLY: System.arraycopy(lines, 0, newLines, 0, lines.length);
// CPPONLY: lines = newLines;
}
names[length] = name;
values[length] = value;
// CPPONLY: lines[length] = line;
length++;
}
void clear(int m) {
for (int i = 0; i < length; i++) {
names[i].release();
names[i] = null;
Portability.releaseString(values[i]);
values[i] = null;
}
length = 0;
mode = m;
// [NOCPP[
idValue = null;
for (int i = 0; i < xmlnsLength; i++) {
xmlnsNames[i] = null;
xmlnsValues[i] = null;
}
xmlnsLength = 0;
// ]NOCPP]
}
/**
* This is used in C++ to release special <code>isindex</code>
* attribute values whose ownership is not transferred.
*/
void releaseValue(int i) {
Portability.releaseString(values[i]);
}
/**
* This is only used for <code>AttributeName</code> ownership transfer
* in the isindex case to avoid freeing custom names twice in C++.
*/
void clearWithoutReleasingContents() {
for (int i = 0; i < length; i++) {
names[i] = null;
values[i] = null;
}
length = 0;
}
boolean contains(AttributeName name) {
for (int i = 0; i < length; i++) {
if (name.equalsAnother(names[i])) {
return true;
}
}
// [NOCPP[
for (int i = 0; i < xmlnsLength; i++) {
if (name.equalsAnother(xmlnsNames[i])) {
return true;
}
}
// ]NOCPP]
return false;
}
public void adjustForMath() {
mode = AttributeName.MATHML;
}
public void adjustForSvg() {
mode = AttributeName.SVG;
}
public HtmlAttributes cloneAttributes(Interner interner)
throws SAXException {
assert (length == 0
// [NOCPP[
&& xmlnsLength == 0
// ]NOCPP]
)
|| mode == 0 || mode == 3;
HtmlAttributes clone = new HtmlAttributes(0);
for (int i = 0; i < length; i++) {
clone.addAttribute(names[i].cloneAttributeName(interner),
Portability.newStringFromString(values[i])
// [NOCPP[
, XmlViolationPolicy.ALLOW
// ]NOCPP]
// CPPONLY: , lines[i]
);
}
// [NOCPP[
for (int i = 0; i < xmlnsLength; i++) {
clone.addAttribute(xmlnsNames[i], xmlnsValues[i],
XmlViolationPolicy.ALLOW);
}
// ]NOCPP]
return clone; // XXX!!!
}
public boolean equalsAnother(HtmlAttributes other) {
assert mode == 0 || mode == 3 : "Trying to compare attributes in foreign content.";
int otherLength = other.getLength();
if (length != otherLength) {
return false;
}
for (int i = 0; i < length; i++) {
// Work around the limitations of C++
boolean found = false;
// The comparing just the local names is OK, since these attribute
// holders are both supposed to belong to HTML formatting elements
@Local String ownLocal = names[i].getLocal(AttributeName.HTML);
for (int j = 0; j < otherLength; j++) {
if (ownLocal == other.names[j].getLocal(AttributeName.HTML)) {
found = true;
if (!Portability.stringEqualsString(values[i], other.values[j])) {
return false;
}
}
}
if (!found) {
return false;
}
}
return true;
}
// [NOCPP[
void processNonNcNames(TreeBuilder<?> treeBuilder, XmlViolationPolicy namePolicy) throws SAXException {
for (int i = 0; i < length; i++) {
AttributeName attName = names[i];
if (!attName.isNcName(mode)) {
String name = attName.getLocal(mode);
switch (namePolicy) {
case ALTER_INFOSET:
names[i] = AttributeName.create(NCName.escapeName(name));
// fall through
case ALLOW:
if (attName != AttributeName.XML_LANG) {
treeBuilder.warn("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0.");
}
break;
case FATAL:
treeBuilder.fatal("Attribute \u201C" + name + "\u201D is not serializable as XML 1.0.");
break;
}
}
}
}
public void merge(HtmlAttributes attributes) throws SAXException {
int len = attributes.getLength();
for (int i = 0; i < len; i++) {
AttributeName name = attributes.getAttributeNameNoBoundsCheck(i);
if (!contains(name)) {
addAttribute(name, attributes.getValueNoBoundsCheck(i), XmlViolationPolicy.ALLOW);
}
}
}
// ]NOCPP]
}

View File

@ -1,854 +0,0 @@
/*
* Copyright (c) 2007 Henri Sivonen
* Copyright (c) 2008-2015 Mozilla Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package nu.validator.htmlparser.impl;
import java.io.IOException;
import nu.validator.htmlparser.annotation.Auto;
import nu.validator.htmlparser.annotation.Inline;
import nu.validator.htmlparser.common.ByteReadable;
import org.xml.sax.SAXException;
public abstract class MetaScanner {
/**
* Constant for "charset".
*/
private static final char[] CHARSET = { 'h', 'a', 'r', 's', 'e', 't' };
/**
* Constant for "content".
*/
private static final char[] CONTENT = { 'o', 'n', 't', 'e', 'n', 't' };
/**
* Constant for "http-equiv".
*/
private static final char[] HTTP_EQUIV = { 't', 't', 'p', '-', 'e', 'q',
'u', 'i', 'v' };
/**
* Constant for "content-type".
*/
private static final char[] CONTENT_TYPE = { 'c', 'o', 'n', 't', 'e', 'n',
't', '-', 't', 'y', 'p', 'e' };
private static final int NO = 0;
private static final int M = 1;
private static final int E = 2;
private static final int T = 3;
private static final int A = 4;
private static final int DATA = 0;
private static final int TAG_OPEN = 1;
private static final int SCAN_UNTIL_GT = 2;
private static final int TAG_NAME = 3;
private static final int BEFORE_ATTRIBUTE_NAME = 4;
private static final int ATTRIBUTE_NAME = 5;
private static final int AFTER_ATTRIBUTE_NAME = 6;
private static final int BEFORE_ATTRIBUTE_VALUE = 7;
private static final int ATTRIBUTE_VALUE_DOUBLE_QUOTED = 8;
private static final int ATTRIBUTE_VALUE_SINGLE_QUOTED = 9;
private static final int ATTRIBUTE_VALUE_UNQUOTED = 10;
private static final int AFTER_ATTRIBUTE_VALUE_QUOTED = 11;
private static final int MARKUP_DECLARATION_OPEN = 13;
private static final int MARKUP_DECLARATION_HYPHEN = 14;
private static final int COMMENT_START = 15;
private static final int COMMENT_START_DASH = 16;
private static final int COMMENT = 17;
private static final int COMMENT_END_DASH = 18;
private static final int COMMENT_END = 19;
private static final int SELF_CLOSING_START_TAG = 20;
private static final int HTTP_EQUIV_NOT_SEEN = 0;
private static final int HTTP_EQUIV_CONTENT_TYPE = 1;
private static final int HTTP_EQUIV_OTHER = 2;
/**
* The data source.
*/
protected ByteReadable readable;
/**
* The state of the state machine that recognizes the tag name "meta".
*/
private int metaState = NO;
/**
* The current position in recognizing the attribute name "content".
*/
private int contentIndex = Integer.MAX_VALUE;
/**
* The current position in recognizing the attribute name "charset".
*/
private int charsetIndex = Integer.MAX_VALUE;
/**
* The current position in recognizing the attribute name "http-equive".
*/
private int httpEquivIndex = Integer.MAX_VALUE;
/**
* The current position in recognizing the attribute value "content-type".
*/
private int contentTypeIndex = Integer.MAX_VALUE;
/**
* The tokenizer state.
*/
protected int stateSave = DATA;
/**
* The currently filled length of strBuf.
*/
private int strBufLen;
/**
* Accumulation buffer for attribute values.
*/
private @Auto char[] strBuf;
private String content;
private String charset;
private int httpEquivState;
// CPPONLY: private TreeBuilder treeBuilder;
public MetaScanner(
// CPPONLY: TreeBuilder tb
) {
this.readable = null;
this.metaState = NO;
this.contentIndex = Integer.MAX_VALUE;
this.charsetIndex = Integer.MAX_VALUE;
this.httpEquivIndex = Integer.MAX_VALUE;
this.contentTypeIndex = Integer.MAX_VALUE;
this.stateSave = DATA;
this.strBufLen = 0;
this.strBuf = new char[36];
this.content = null;
this.charset = null;
this.httpEquivState = HTTP_EQUIV_NOT_SEEN;
// CPPONLY: this.treeBuilder = tb;
}
@SuppressWarnings("unused") private void destructor() {
Portability.releaseString(content);
Portability.releaseString(charset);
}
// [NOCPP[
/**
* Reads a byte from the data source.
*
* -1 means end.
* @return
* @throws IOException
*/
protected int read() throws IOException {
return readable.readByte();
}
// ]NOCPP]
// WARNING When editing this, makes sure the bytecode length shown by javap
// stays under 8000 bytes!
/**
* The runs the meta scanning algorithm.
*/
protected final void stateLoop(int state)
throws SAXException, IOException {
int c = -1;
boolean reconsume = false;
stateloop: for (;;) {
switch (state) {
case DATA:
dataloop: for (;;) {
if (reconsume) {
reconsume = false;
} else {
c = read();
}
switch (c) {
case -1:
break stateloop;
case '<':
state = MetaScanner.TAG_OPEN;
break dataloop; // FALL THROUGH continue
// stateloop;
default:
continue;
}
}
// WARNING FALLTHRU CASE TRANSITION: DON'T REORDER
case TAG_OPEN:
tagopenloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case 'm':
case 'M':
metaState = M;
state = MetaScanner.TAG_NAME;
break tagopenloop;
// continue stateloop;
case '!':
state = MetaScanner.MARKUP_DECLARATION_OPEN;
continue stateloop;
case '?':
case '/':
state = MetaScanner.SCAN_UNTIL_GT;
continue stateloop;
case '>':
state = MetaScanner.DATA;
continue stateloop;
default:
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
metaState = NO;
state = MetaScanner.TAG_NAME;
break tagopenloop;
// continue stateloop;
}
state = MetaScanner.DATA;
reconsume = true;
continue stateloop;
}
}
// FALL THROUGH DON'T REORDER
case TAG_NAME:
tagnameloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case ' ':
case '\t':
case '\n':
case '\u000C':
state = MetaScanner.BEFORE_ATTRIBUTE_NAME;
break tagnameloop;
// continue stateloop;
case '/':
state = MetaScanner.SELF_CLOSING_START_TAG;
continue stateloop;
case '>':
state = MetaScanner.DATA;
continue stateloop;
case 'e':
case 'E':
if (metaState == M) {
metaState = E;
} else {
metaState = NO;
}
continue;
case 't':
case 'T':
if (metaState == E) {
metaState = T;
} else {
metaState = NO;
}
continue;
case 'a':
case 'A':
if (metaState == T) {
metaState = A;
} else {
metaState = NO;
}
continue;
default:
metaState = NO;
continue;
}
}
// FALLTHRU DON'T REORDER
case BEFORE_ATTRIBUTE_NAME:
beforeattributenameloop: for (;;) {
if (reconsume) {
reconsume = false;
} else {
c = read();
}
/*
* Consume the next input character:
*/
switch (c) {
case -1:
break stateloop;
case ' ':
case '\t':
case '\n':
case '\u000C':
continue;
case '/':
state = MetaScanner.SELF_CLOSING_START_TAG;
continue stateloop;
case '>':
if (handleTag()) {
break stateloop;
}
state = DATA;
continue stateloop;
case 'c':
case 'C':
contentIndex = 0;
charsetIndex = 0;
httpEquivIndex = Integer.MAX_VALUE;
contentTypeIndex = Integer.MAX_VALUE;
state = MetaScanner.ATTRIBUTE_NAME;
break beforeattributenameloop;
case 'h':
case 'H':
contentIndex = Integer.MAX_VALUE;
charsetIndex = Integer.MAX_VALUE;
httpEquivIndex = 0;
contentTypeIndex = Integer.MAX_VALUE;
state = MetaScanner.ATTRIBUTE_NAME;
break beforeattributenameloop;
default:
contentIndex = Integer.MAX_VALUE;
charsetIndex = Integer.MAX_VALUE;
httpEquivIndex = Integer.MAX_VALUE;
contentTypeIndex = Integer.MAX_VALUE;
state = MetaScanner.ATTRIBUTE_NAME;
break beforeattributenameloop;
// continue stateloop;
}
}
// FALLTHRU DON'T REORDER
case ATTRIBUTE_NAME:
attributenameloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case ' ':
case '\t':
case '\n':
case '\u000C':
state = MetaScanner.AFTER_ATTRIBUTE_NAME;
continue stateloop;
case '/':
state = MetaScanner.SELF_CLOSING_START_TAG;
continue stateloop;
case '=':
strBufLen = 0;
contentTypeIndex = 0;
state = MetaScanner.BEFORE_ATTRIBUTE_VALUE;
break attributenameloop;
// continue stateloop;
case '>':
if (handleTag()) {
break stateloop;
}
state = MetaScanner.DATA;
continue stateloop;
default:
if (metaState == A) {
if (c >= 'A' && c <= 'Z') {
c += 0x20;
}
if (contentIndex < CONTENT.length && c == CONTENT[contentIndex]) {
++contentIndex;
} else {
contentIndex = Integer.MAX_VALUE;
}
if (charsetIndex < CHARSET.length && c == CHARSET[charsetIndex]) {
++charsetIndex;
} else {
charsetIndex = Integer.MAX_VALUE;
}
if (httpEquivIndex < HTTP_EQUIV.length && c == HTTP_EQUIV[httpEquivIndex]) {
++httpEquivIndex;
} else {
httpEquivIndex = Integer.MAX_VALUE;
}
}
continue;
}
}
// FALLTHRU DON'T REORDER
case BEFORE_ATTRIBUTE_VALUE:
beforeattributevalueloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case ' ':
case '\t':
case '\n':
case '\u000C':
continue;
case '"':
state = MetaScanner.ATTRIBUTE_VALUE_DOUBLE_QUOTED;
break beforeattributevalueloop;
// continue stateloop;
case '\'':
state = MetaScanner.ATTRIBUTE_VALUE_SINGLE_QUOTED;
continue stateloop;
case '>':
if (handleTag()) {
break stateloop;
}
state = MetaScanner.DATA;
continue stateloop;
default:
handleCharInAttributeValue(c);
state = MetaScanner.ATTRIBUTE_VALUE_UNQUOTED;
continue stateloop;
}
}
// FALLTHRU DON'T REORDER
case ATTRIBUTE_VALUE_DOUBLE_QUOTED:
attributevaluedoublequotedloop: for (;;) {
if (reconsume) {
reconsume = false;
} else {
c = read();
}
switch (c) {
case -1:
break stateloop;
case '"':
handleAttributeValue();
state = MetaScanner.AFTER_ATTRIBUTE_VALUE_QUOTED;
break attributevaluedoublequotedloop;
// continue stateloop;
default:
handleCharInAttributeValue(c);
continue;
}
}
// FALLTHRU DON'T REORDER
case AFTER_ATTRIBUTE_VALUE_QUOTED:
afterattributevaluequotedloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case ' ':
case '\t':
case '\n':
case '\u000C':
state = MetaScanner.BEFORE_ATTRIBUTE_NAME;
continue stateloop;
case '/':
state = MetaScanner.SELF_CLOSING_START_TAG;
break afterattributevaluequotedloop;
// continue stateloop;
case '>':
if (handleTag()) {
break stateloop;
}
state = MetaScanner.DATA;
continue stateloop;
default:
state = MetaScanner.BEFORE_ATTRIBUTE_NAME;
reconsume = true;
continue stateloop;
}
}
// FALLTHRU DON'T REORDER
case SELF_CLOSING_START_TAG:
c = read();
switch (c) {
case -1:
break stateloop;
case '>':
if (handleTag()) {
break stateloop;
}
state = MetaScanner.DATA;
continue stateloop;
default:
state = MetaScanner.BEFORE_ATTRIBUTE_NAME;
reconsume = true;
continue stateloop;
}
// XXX reorder point
case ATTRIBUTE_VALUE_UNQUOTED:
for (;;) {
if (reconsume) {
reconsume = false;
} else {
c = read();
}
switch (c) {
case -1:
break stateloop;
case ' ':
case '\t':
case '\n':
case '\u000C':
handleAttributeValue();
state = MetaScanner.BEFORE_ATTRIBUTE_NAME;
continue stateloop;
case '>':
handleAttributeValue();
if (handleTag()) {
break stateloop;
}
state = MetaScanner.DATA;
continue stateloop;
default:
handleCharInAttributeValue(c);
continue;
}
}
// XXX reorder point
case AFTER_ATTRIBUTE_NAME:
for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case ' ':
case '\t':
case '\n':
case '\u000C':
continue;
case '/':
handleAttributeValue();
state = MetaScanner.SELF_CLOSING_START_TAG;
continue stateloop;
case '=':
strBufLen = 0;
contentTypeIndex = 0;
state = MetaScanner.BEFORE_ATTRIBUTE_VALUE;
continue stateloop;
case '>':
handleAttributeValue();
if (handleTag()) {
break stateloop;
}
state = MetaScanner.DATA;
continue stateloop;
case 'c':
case 'C':
contentIndex = 0;
charsetIndex = 0;
state = MetaScanner.ATTRIBUTE_NAME;
continue stateloop;
default:
contentIndex = Integer.MAX_VALUE;
charsetIndex = Integer.MAX_VALUE;
state = MetaScanner.ATTRIBUTE_NAME;
continue stateloop;
}
}
// XXX reorder point
case MARKUP_DECLARATION_OPEN:
markupdeclarationopenloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case '-':
state = MetaScanner.MARKUP_DECLARATION_HYPHEN;
break markupdeclarationopenloop;
// continue stateloop;
default:
state = MetaScanner.SCAN_UNTIL_GT;
reconsume = true;
continue stateloop;
}
}
// FALLTHRU DON'T REORDER
case MARKUP_DECLARATION_HYPHEN:
markupdeclarationhyphenloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case '-':
state = MetaScanner.COMMENT_START;
break markupdeclarationhyphenloop;
// continue stateloop;
default:
state = MetaScanner.SCAN_UNTIL_GT;
reconsume = true;
continue stateloop;
}
}
// FALLTHRU DON'T REORDER
case COMMENT_START:
commentstartloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case '-':
state = MetaScanner.COMMENT_START_DASH;
continue stateloop;
case '>':
state = MetaScanner.DATA;
continue stateloop;
default:
state = MetaScanner.COMMENT;
break commentstartloop;
// continue stateloop;
}
}
// FALLTHRU DON'T REORDER
case COMMENT:
commentloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case '-':
state = MetaScanner.COMMENT_END_DASH;
break commentloop;
// continue stateloop;
default:
continue;
}
}
// FALLTHRU DON'T REORDER
case COMMENT_END_DASH:
commentenddashloop: for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case '-':
state = MetaScanner.COMMENT_END;
break commentenddashloop;
// continue stateloop;
default:
state = MetaScanner.COMMENT;
continue stateloop;
}
}
// FALLTHRU DON'T REORDER
case COMMENT_END:
for (;;) {
c = read();
switch (c) {
case -1:
break stateloop;
case '>':
state = MetaScanner.DATA;
continue stateloop;
case '-':
continue;
default:
state = MetaScanner.COMMENT;
continue stateloop;
}
}
// XXX reorder point
case COMMENT_START_DASH:
c = read();
switch (c) {
case -1:
break stateloop;
case '-':
state = MetaScanner.COMMENT_END;
continue stateloop;
case '>':
state = MetaScanner.DATA;
continue stateloop;
default:
state = MetaScanner.COMMENT;
continue stateloop;
}
// XXX reorder point
case ATTRIBUTE_VALUE_SINGLE_QUOTED:
for (;;) {
if (reconsume) {
reconsume = false;
} else {
c = read();
}
switch (c) {
case -1:
break stateloop;
case '\'':
handleAttributeValue();
state = MetaScanner.AFTER_ATTRIBUTE_VALUE_QUOTED;
continue stateloop;
default:
handleCharInAttributeValue(c);
continue;
}
}
// XXX reorder point
case SCAN_UNTIL_GT:
for (;;) {
if (reconsume) {
reconsume = false;
} else {
c = read();
}
switch (c) {
case -1:
break stateloop;
case '>':
state = MetaScanner.DATA;
continue stateloop;
default:
continue;
}
}
}
}
stateSave = state;
}
private void handleCharInAttributeValue(int c) {
if (metaState == A) {
if (contentIndex == CONTENT.length || charsetIndex == CHARSET.length) {
addToBuffer(c);
} else if (httpEquivIndex == HTTP_EQUIV.length) {
if (contentTypeIndex < CONTENT_TYPE.length && toAsciiLowerCase(c) == CONTENT_TYPE[contentTypeIndex]) {
++contentTypeIndex;
} else {
contentTypeIndex = Integer.MAX_VALUE;
}
}
}
}
@Inline private int toAsciiLowerCase(int c) {
if (c >= 'A' && c <= 'Z') {
return c + 0x20;
}
return c;
}
/**
* Adds a character to the accumulation buffer.
* @param c the character to add
*/
private void addToBuffer(int c) {
if (strBufLen == strBuf.length) {
char[] newBuf = new char[strBuf.length + (strBuf.length << 1)];
System.arraycopy(strBuf, 0, newBuf, 0, strBuf.length);
strBuf = newBuf;
}
strBuf[strBufLen++] = (char)c;
}
/**
* Attempts to extract a charset name from the accumulation buffer.
* @return <code>true</code> if successful
* @throws SAXException
*/
private void handleAttributeValue() throws SAXException {
if (metaState != A) {
return;
}
if (contentIndex == CONTENT.length && content == null) {
content = Portability.newStringFromBuffer(strBuf, 0, strBufLen
// CPPONLY: , treeBuilder
);
return;
}
if (charsetIndex == CHARSET.length && charset == null) {
charset = Portability.newStringFromBuffer(strBuf, 0, strBufLen
// CPPONLY: , treeBuilder
);
return;
}
if (httpEquivIndex == HTTP_EQUIV.length
&& httpEquivState == HTTP_EQUIV_NOT_SEEN) {
httpEquivState = (contentTypeIndex == CONTENT_TYPE.length) ? HTTP_EQUIV_CONTENT_TYPE
: HTTP_EQUIV_OTHER;
return;
}
}
private boolean handleTag() throws SAXException {
boolean stop = handleTagInner();
Portability.releaseString(content);
content = null;
Portability.releaseString(charset);
charset = null;
httpEquivState = HTTP_EQUIV_NOT_SEEN;
return stop;
}
private boolean handleTagInner() throws SAXException {
if (charset != null && tryCharset(charset)) {
return true;
}
if (content != null && httpEquivState == HTTP_EQUIV_CONTENT_TYPE) {
String extract = TreeBuilder.extractCharsetFromContent(content
// CPPONLY: , treeBuilder
);
if (extract == null) {
return false;
}
boolean success = tryCharset(extract);
Portability.releaseString(extract);
return success;
}
return false;
}
/**
* Tries to switch to an encoding.
*
* @param encoding
* @return <code>true</code> if successful
* @throws SAXException
*/
protected abstract boolean tryCharset(String encoding) throws SAXException;
}

View File

@ -1,150 +0,0 @@
/*
* Copyright (c) 2008-2015 Mozilla Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package nu.validator.htmlparser.impl;
import nu.validator.htmlparser.annotation.Literal;
import nu.validator.htmlparser.annotation.Local;
import nu.validator.htmlparser.annotation.NoLength;
import nu.validator.htmlparser.common.Interner;
public final class Portability {
// Allocating methods
/**
* Allocates a new local name object. In C++, the refcount must be set up in such a way that
* calling <code>releaseLocal</code> on the return value balances the refcount set by this method.
*/
public static @Local String newLocalNameFromBuffer(@NoLength char[] buf, int offset, int length, Interner interner) {
return new String(buf, offset, length).intern();
}
public static String newStringFromBuffer(@NoLength char[] buf, int offset, int length
// CPPONLY: , TreeBuilder treeBuilder
) {
return new String(buf, offset, length);
}
public static String newEmptyString() {
return "";
}
public static String newStringFromLiteral(@Literal String literal) {
return literal;
}
public static String newStringFromString(String string) {
return string;
}
// XXX get rid of this
public static char[] newCharArrayFromLocal(@Local String local) {
return local.toCharArray();
}
public static char[] newCharArrayFromString(String string) {
return string.toCharArray();
}
public static @Local String newLocalFromLocal(@Local String local, Interner interner) {
return local;
}
// Deallocation methods
public static void releaseString(String str) {
// No-op in Java
}
// Comparison methods
public static boolean localEqualsBuffer(@Local String local, @NoLength char[] buf, int offset, int length) {
if (local.length() != length) {
return false;
}
for (int i = 0; i < length; i++) {
if (local.charAt(i) != buf[offset + i]) {
return false;
}
}
return true;
}
public static boolean lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(@Literal String lowerCaseLiteral,
String string) {
if (string == null) {
return false;
}
if (lowerCaseLiteral.length() > string.length()) {
return false;
}
for (int i = 0; i < lowerCaseLiteral.length(); i++) {
char c0 = lowerCaseLiteral.charAt(i);
char c1 = string.charAt(i);
if (c1 >= 'A' && c1 <= 'Z') {
c1 += 0x20;
}
if (c0 != c1) {
return false;
}
}
return true;
}
public static boolean lowerCaseLiteralEqualsIgnoreAsciiCaseString(@Literal String lowerCaseLiteral,
String string) {
if (string == null) {
return false;
}
if (lowerCaseLiteral.length() != string.length()) {
return false;
}
for (int i = 0; i < lowerCaseLiteral.length(); i++) {
char c0 = lowerCaseLiteral.charAt(i);
char c1 = string.charAt(i);
if (c1 >= 'A' && c1 <= 'Z') {
c1 += 0x20;
}
if (c0 != c1) {
return false;
}
}
return true;
}
public static boolean literalEqualsString(@Literal String literal, String string) {
return literal.equals(string);
}
public static boolean stringEqualsString(String one, String other) {
return one.equals(other);
}
public static void delete(Object o) {
}
public static void deleteArray(Object o) {
}
}

View File

@ -1,6 +0,0 @@
The .java files in this directory were placed here by the Java-to-C++
translator that lives in parser/html/java/translator. Together they represent
a snapshot of the Java code that was translated to produce the corresponding
.h and .cpp files in the parent directory. Changing these .java files is not
worthwhile, as they will just be overwritten by the next translation. See
parser/html/java/README.txt for information about performing the translation.

View File

@ -1,295 +0,0 @@
/*
* Copyright (c) 2007 Henri Sivonen
* Copyright (c) 2007-2011 Mozilla Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package nu.validator.htmlparser.impl;
import nu.validator.htmlparser.annotation.Inline;
import nu.validator.htmlparser.annotation.Local;
import nu.validator.htmlparser.annotation.NsUri;
final class StackNode<T> {
final int flags;
final @Local String name;
final @Local String popName;
final @NsUri String ns;
final T node;
// Only used on the list of formatting elements
HtmlAttributes attributes;
private int refcount = 1;
// [NOCPP[
private final TaintableLocatorImpl locator;
public TaintableLocatorImpl getLocator() {
return locator;
}
// ]NOCPP]
@Inline public int getFlags() {
return flags;
}
public int getGroup() {
return flags & ElementName.GROUP_MASK;
}
public boolean isScoping() {
return (flags & ElementName.SCOPING) != 0;
}
public boolean isSpecial() {
return (flags & ElementName.SPECIAL) != 0;
}
public boolean isFosterParenting() {
return (flags & ElementName.FOSTER_PARENTING) != 0;
}
public boolean isHtmlIntegrationPoint() {
return (flags & ElementName.HTML_INTEGRATION_POINT) != 0;
}
// [NOCPP[
public boolean isOptionalEndTag() {
return (flags & ElementName.OPTIONAL_END_TAG) != 0;
}
// ]NOCPP]
/**
* Constructor for copying. This doesn't take another <code>StackNode</code>
* because in C++ the caller is reponsible for reobtaining the local names
* from another interner.
*
* @param flags
* @param ns
* @param name
* @param node
* @param popName
* @param attributes
*/
StackNode(int flags, @NsUri String ns, @Local String name, T node,
@Local String popName, HtmlAttributes attributes
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
this.flags = flags;
this.name = name;
this.popName = popName;
this.ns = ns;
this.node = node;
this.attributes = attributes;
this.refcount = 1;
// [NOCPP[
this.locator = locator;
// ]NOCPP]
}
/**
* Short hand for well-known HTML elements.
*
* @param elementName
* @param node
*/
StackNode(ElementName elementName, T node
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
this.flags = elementName.getFlags();
this.name = elementName.name;
this.popName = elementName.name;
this.ns = "http://www.w3.org/1999/xhtml";
this.node = node;
this.attributes = null;
this.refcount = 1;
assert !elementName.isCustom() : "Don't use this constructor for custom elements.";
// [NOCPP[
this.locator = locator;
// ]NOCPP]
}
/**
* Constructor for HTML formatting elements.
*
* @param elementName
* @param node
* @param attributes
*/
StackNode(ElementName elementName, T node, HtmlAttributes attributes
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
this.flags = elementName.getFlags();
this.name = elementName.name;
this.popName = elementName.name;
this.ns = "http://www.w3.org/1999/xhtml";
this.node = node;
this.attributes = attributes;
this.refcount = 1;
assert !elementName.isCustom() : "Don't use this constructor for custom elements.";
// [NOCPP[
this.locator = locator;
// ]NOCPP]
}
/**
* The common-case HTML constructor.
*
* @param elementName
* @param node
* @param popName
*/
StackNode(ElementName elementName, T node, @Local String popName
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
this.flags = elementName.getFlags();
this.name = elementName.name;
this.popName = popName;
this.ns = "http://www.w3.org/1999/xhtml";
this.node = node;
this.attributes = null;
this.refcount = 1;
// [NOCPP[
this.locator = locator;
// ]NOCPP]
}
/**
* Constructor for SVG elements. Note that the order of the arguments is
* what distinguishes this from the HTML constructor. This is ugly, but
* AFAICT the least disruptive way to make this work with Java's generics
* and without unnecessary branches. :-(
*
* @param elementName
* @param popName
* @param node
*/
StackNode(ElementName elementName, @Local String popName, T node
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
this.flags = prepareSvgFlags(elementName.getFlags());
this.name = elementName.name;
this.popName = popName;
this.ns = "http://www.w3.org/2000/svg";
this.node = node;
this.attributes = null;
this.refcount = 1;
// [NOCPP[
this.locator = locator;
// ]NOCPP]
}
/**
* Constructor for MathML.
*
* @param elementName
* @param node
* @param popName
* @param markAsIntegrationPoint
*/
StackNode(ElementName elementName, T node, @Local String popName,
boolean markAsIntegrationPoint
// [NOCPP[
, TaintableLocatorImpl locator
// ]NOCPP]
) {
this.flags = prepareMathFlags(elementName.getFlags(),
markAsIntegrationPoint);
this.name = elementName.name;
this.popName = popName;
this.ns = "http://www.w3.org/1998/Math/MathML";
this.node = node;
this.attributes = null;
this.refcount = 1;
// [NOCPP[
this.locator = locator;
// ]NOCPP]
}
private static int prepareSvgFlags(int flags) {
flags &= ~(ElementName.FOSTER_PARENTING | ElementName.SCOPING
| ElementName.SPECIAL | ElementName.OPTIONAL_END_TAG);
if ((flags & ElementName.SCOPING_AS_SVG) != 0) {
flags |= (ElementName.SCOPING | ElementName.SPECIAL | ElementName.HTML_INTEGRATION_POINT);
}
return flags;
}
private static int prepareMathFlags(int flags,
boolean markAsIntegrationPoint) {
flags &= ~(ElementName.FOSTER_PARENTING | ElementName.SCOPING
| ElementName.SPECIAL | ElementName.OPTIONAL_END_TAG);
if ((flags & ElementName.SCOPING_AS_MATHML) != 0) {
flags |= (ElementName.SCOPING | ElementName.SPECIAL);
}
if (markAsIntegrationPoint) {
flags |= ElementName.HTML_INTEGRATION_POINT;
}
return flags;
}
@SuppressWarnings("unused") private void destructor() {
Portability.delete(attributes);
}
public void dropAttributes() {
attributes = null;
}
// [NOCPP[
/**
* @see java.lang.Object#toString()
*/
@Override public @Local String toString() {
return name;
}
// ]NOCPP]
public void retain() {
refcount++;
}
public void release() {
refcount--;
if (refcount == 0) {
Portability.delete(this);
}
}
}

View File

@ -1,204 +0,0 @@
/*
* Copyright (c) 2009-2010 Mozilla Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package nu.validator.htmlparser.impl;
import nu.validator.htmlparser.annotation.Auto;
public class StateSnapshot<T> implements TreeBuilderState<T> {
private final @Auto StackNode<T>[] stack;
private final @Auto StackNode<T>[] listOfActiveFormattingElements;
private final @Auto int[] templateModeStack;
private final T formPointer;
private final T headPointer;
private final T deepTreeSurrogateParent;
private final int mode;
private final int originalMode;
private final boolean framesetOk;
private final boolean needToDropLF;
private final boolean quirks;
/**
* @param stack
* @param listOfActiveFormattingElements
* @param templateModeStack
* @param formPointer
* @param headPointer
* @param deepTreeSurrogateParent
* @param mode
* @param originalMode
* @param framesetOk
* @param needToDropLF
* @param quirks
*/
StateSnapshot(StackNode<T>[] stack,
StackNode<T>[] listOfActiveFormattingElements, int[] templateModeStack, T formPointer,
T headPointer, T deepTreeSurrogateParent, int mode, int originalMode,
boolean framesetOk, boolean needToDropLF, boolean quirks) {
this.stack = stack;
this.listOfActiveFormattingElements = listOfActiveFormattingElements;
this.templateModeStack = templateModeStack;
this.formPointer = formPointer;
this.headPointer = headPointer;
this.deepTreeSurrogateParent = deepTreeSurrogateParent;
this.mode = mode;
this.originalMode = originalMode;
this.framesetOk = framesetOk;
this.needToDropLF = needToDropLF;
this.quirks = quirks;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getStack()
*/
public StackNode<T>[] getStack() {
return stack;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getTemplateModeStack()
*/
public int[] getTemplateModeStack() {
return templateModeStack;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElements()
*/
public StackNode<T>[] getListOfActiveFormattingElements() {
return listOfActiveFormattingElements;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getFormPointer()
*/
public T getFormPointer() {
return formPointer;
}
/**
* Returns the headPointer.
*
* @return the headPointer
*/
public T getHeadPointer() {
return headPointer;
}
/**
* Returns the deepTreeSurrogateParent.
*
* @return the deepTreeSurrogateParent
*/
public T getDeepTreeSurrogateParent() {
return deepTreeSurrogateParent;
}
/**
* Returns the mode.
*
* @return the mode
*/
public int getMode() {
return mode;
}
/**
* Returns the originalMode.
*
* @return the originalMode
*/
public int getOriginalMode() {
return originalMode;
}
/**
* Returns the framesetOk.
*
* @return the framesetOk
*/
public boolean isFramesetOk() {
return framesetOk;
}
/**
* Returns the needToDropLF.
*
* @return the needToDropLF
*/
public boolean isNeedToDropLF() {
return needToDropLF;
}
/**
* Returns the quirks.
*
* @return the quirks
*/
public boolean isQuirks() {
return quirks;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElementsLength()
*/
public int getListOfActiveFormattingElementsLength() {
return listOfActiveFormattingElements.length;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getStackLength()
*/
public int getStackLength() {
return stack.length;
}
/**
* @see nu.validator.htmlparser.impl.TreeBuilderState#getTemplateModeStackLength()
*/
public int getTemplateModeStackLength() {
return templateModeStack.length;
}
@SuppressWarnings("unused") private void destructor() {
for (int i = 0; i < stack.length; i++) {
stack[i].release();
}
for (int i = 0; i < listOfActiveFormattingElements.length; i++) {
if (listOfActiveFormattingElements[i] != null) {
listOfActiveFormattingElements[i].release();
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,151 +0,0 @@
/*
* Copyright (c) 2008-2010 Mozilla Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
package nu.validator.htmlparser.impl;
import nu.validator.htmlparser.annotation.NoLength;
/**
* An UTF-16 buffer that knows the start and end indeces of its unconsumed
* content.
*
* @version $Id$
* @author hsivonen
*/
public final class UTF16Buffer {
/**
* The backing store of the buffer. May be larger than the logical content
* of this <code>UTF16Buffer</code>.
*/
private final @NoLength char[] buffer;
/**
* The index of the first unconsumed character in the backing buffer.
*/
private int start;
/**
* The index of the slot immediately after the last character in the backing
* buffer that is part of the logical content of this
* <code>UTF16Buffer</code>.
*/
private int end;
//[NOCPP[
/**
* Constructor for wrapping an existing UTF-16 code unit array.
*
* @param buffer
* the backing buffer
* @param start
* the index of the first character to consume
* @param end
* the index immediately after the last character to consume
*/
public UTF16Buffer(@NoLength char[] buffer, int start, int end) {
this.buffer = buffer;
this.start = start;
this.end = end;
}
// ]NOCPP]
/**
* Returns the start index.
*
* @return the start index
*/
public int getStart() {
return start;
}
/**
* Sets the start index.
*
* @param start
* the start index
*/
public void setStart(int start) {
this.start = start;
}
/**
* Returns the backing buffer.
*
* @return the backing buffer
*/
public @NoLength char[] getBuffer() {
return buffer;
}
/**
* Returns the end index.
*
* @return the end index
*/
public int getEnd() {
return end;
}
/**
* Checks if the buffer has data left.
*
* @return <code>true</code> if there's data left
*/
public boolean hasMore() {
return start < end;
}
/**
* Returns <code>end - start</code>.
*
* @return <code>end - start</code>
*/
public int getLength() {
return end - start;
}
/**
* Adjusts the start index to skip over the first character if it is a line
* feed and the previous character was a carriage return.
*
* @param lastWasCR
* whether the previous character was a carriage return
*/
public void adjust(boolean lastWasCR) {
if (lastWasCR && buffer[start] == '\n') {
start++;
}
}
/**
* Sets the end index.
*
* @param end
* the end index
*/
public void setEnd(int end) {
this.end = end;
}
}

View File

@ -21,11 +21,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit AttributeName.java instead and regenerate.
*/
#define nsHtml5AttributeName_cpp__
#include "nsIAtom.h"

View File

@ -21,11 +21,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit AttributeName.java instead and regenerate.
*/
#ifndef nsHtml5AttributeName_h
#define nsHtml5AttributeName_h

View File

@ -21,11 +21,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit ElementName.java instead and regenerate.
*/
#define nsHtml5ElementName_cpp__
#include "nsIAtom.h"

View File

@ -21,11 +21,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit ElementName.java instead and regenerate.
*/
#ifndef nsHtml5ElementName_h
#define nsHtml5ElementName_h

View File

@ -22,11 +22,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit HtmlAttributes.java instead and regenerate.
*/
#define nsHtml5HtmlAttributes_cpp__
#include "nsIAtom.h"

View File

@ -22,11 +22,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit HtmlAttributes.java instead and regenerate.
*/
#ifndef nsHtml5HtmlAttributes_h
#define nsHtml5HtmlAttributes_h

View File

@ -22,11 +22,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit MetaScanner.java instead and regenerate.
*/
#define nsHtml5MetaScanner_cpp__
#include "nsIAtom.h"

View File

@ -22,11 +22,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit MetaScanner.java instead and regenerate.
*/
#ifndef nsHtml5MetaScanner_h
#define nsHtml5MetaScanner_h

View File

@ -21,11 +21,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit Portability.java instead and regenerate.
*/
#ifndef nsHtml5Portability_h
#define nsHtml5Portability_h

View File

@ -22,11 +22,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit StackNode.java instead and regenerate.
*/
#define nsHtml5StackNode_cpp__
#include "nsIAtom.h"

View File

@ -22,11 +22,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit StackNode.java instead and regenerate.
*/
#ifndef nsHtml5StackNode_h
#define nsHtml5StackNode_h

View File

@ -21,11 +21,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit StateSnapshot.java instead and regenerate.
*/
#define nsHtml5StateSnapshot_cpp__
#include "nsIAtom.h"

View File

@ -21,11 +21,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit StateSnapshot.java instead and regenerate.
*/
#ifndef nsHtml5StateSnapshot_h
#define nsHtml5StateSnapshot_h

View File

@ -24,11 +24,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit Tokenizer.java instead and regenerate.
*/
#define nsHtml5Tokenizer_cpp__
#include "nsIAtom.h"

View File

@ -24,11 +24,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit Tokenizer.java instead and regenerate.
*/
#ifndef nsHtml5Tokenizer_h
#define nsHtml5Tokenizer_h

View File

@ -24,11 +24,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit TreeBuilder.java instead and regenerate.
*/
#define nsHtml5TreeBuilder_cpp__
#include "nsContentUtils.h"

View File

@ -24,11 +24,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit TreeBuilder.java instead and regenerate.
*/
#ifndef nsHtml5TreeBuilder_h
#define nsHtml5TreeBuilder_h

View File

@ -21,11 +21,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit UTF16Buffer.java instead and regenerate.
*/
#define nsHtml5UTF16Buffer_cpp__
#include "nsIAtom.h"

View File

@ -21,11 +21,6 @@
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit UTF16Buffer.java instead and regenerate.
*/
#ifndef nsHtml5UTF16Buffer_h
#define nsHtml5UTF16Buffer_h