xml11entityscanner.java

来自「JAVA 所有包」· Java 代码 · 共 1,525 行 · 第 1/5 页

JAVA
1,525
字号
        }        // scan qualified name        int offset = fCurrentEntity.position;        char ch = fCurrentEntity.ch[offset];                if (XML11Char.isXML11NCNameStart(ch)) {            if (++fCurrentEntity.position == fCurrentEntity.count) {                fCurrentEntity.ch[0] = ch;                offset = 0;                if (load(1, false)) {                    fCurrentEntity.columnNumber++;                    String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);                    qname.setValues(null, name, name, null);                    return true;                }            }        }        else if (XML11Char.isXML11NameHighSurrogate(ch)) {            if (++fCurrentEntity.position == fCurrentEntity.count) {                fCurrentEntity.ch[0] = ch;                offset = 0;                if (load(1, false)) {                    --fCurrentEntity.startPosition;                    --fCurrentEntity.position;                    return false;                }            }            char ch2 = fCurrentEntity.ch[fCurrentEntity.position];            if ( !XMLChar.isLowSurrogate(ch2) ||                 !XML11Char.isXML11NCNameStart(XMLChar.supplemental(ch, ch2)) ) {                --fCurrentEntity.position;                return false;            }            if (++fCurrentEntity.position == fCurrentEntity.count) {                fCurrentEntity.ch[0] = ch;                fCurrentEntity.ch[1] = ch2;                offset = 0;                if (load(2, false)) {                    fCurrentEntity.columnNumber += 2;                    String name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2);                    qname.setValues(null, name, name, null);                    return true;                }            }        }        else {            return false;        }                int index = -1;        boolean sawIncompleteSurrogatePair = false;        do {            ch = fCurrentEntity.ch[fCurrentEntity.position];            if (XML11Char.isXML11Name(ch)) {                if (ch == ':') {                    if (index != -1) {                        break;                    }                    index = fCurrentEntity.position;                }                if (++fCurrentEntity.position == fCurrentEntity.count) {                    int length = fCurrentEntity.position - offset;                    if (length == fCurrentEntity.ch.length) {                        // bad luck we have to resize our buffer                        char[] tmp = new char[fCurrentEntity.ch.length << 1];                        System.arraycopy(fCurrentEntity.ch, offset,                                         tmp, 0, length);                        fCurrentEntity.ch = tmp;                    }                    else {                        System.arraycopy(fCurrentEntity.ch, offset,                                         fCurrentEntity.ch, 0, length);                    }                    if (index != -1) {                        index = index - offset;                    }                    offset = 0;                    if (load(length, false)) {                        break;                    }                }            }            else if (XML11Char.isXML11NameHighSurrogate(ch)) {                if (++fCurrentEntity.position == fCurrentEntity.count) {                    int length = fCurrentEntity.position - offset;                    if (length == fCurrentEntity.ch.length) {                        // bad luck we have to resize our buffer                        char[] tmp = new char[fCurrentEntity.ch.length << 1];                        System.arraycopy(fCurrentEntity.ch, offset,                                         tmp, 0, length);                        fCurrentEntity.ch = tmp;                    }                    else {                        System.arraycopy(fCurrentEntity.ch, offset,                                         fCurrentEntity.ch, 0, length);                    }                    if (index != -1) {                        index = index - offset;                    }                    offset = 0;                    if (load(length, false)) {                        sawIncompleteSurrogatePair = true;                        --fCurrentEntity.startPosition;                        --fCurrentEntity.position;                        break;                    }                }                char ch2 = fCurrentEntity.ch[fCurrentEntity.position];                if ( !XMLChar.isLowSurrogate(ch2) ||                     !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) {                    sawIncompleteSurrogatePair = true;                    --fCurrentEntity.position;                    break;                }                if (++fCurrentEntity.position == fCurrentEntity.count) {                    int length = fCurrentEntity.position - offset;                    if (length == fCurrentEntity.ch.length) {                        // bad luck we have to resize our buffer                        char[] tmp = new char[fCurrentEntity.ch.length << 1];                        System.arraycopy(fCurrentEntity.ch, offset,                                         tmp, 0, length);                        fCurrentEntity.ch = tmp;                    }                    else {                        System.arraycopy(fCurrentEntity.ch, offset,                                         fCurrentEntity.ch, 0, length);                    }                    if (index != -1) {                        index = index - offset;                    }                    offset = 0;                    if (load(length, false)) {                        break;                    }                }            }            else {                break;            }        }        while (true);                int length = fCurrentEntity.position - offset;        fCurrentEntity.columnNumber += length;                if (length > 0) {            String prefix = null;            String localpart = null;            String rawname = fSymbolTable.addSymbol(fCurrentEntity.ch,                                                    offset, length);            if (index != -1) {                int prefixLength = index - offset;                prefix = fSymbolTable.addSymbol(fCurrentEntity.ch,                                                    offset, prefixLength);                int len = length - prefixLength - 1;                int startLocal = index +1;                if (!XML11Char.isXML11NCNameStart(fCurrentEntity.ch[startLocal]) &&                    (!XML11Char.isXML11NameHighSurrogate(fCurrentEntity.ch[startLocal]) ||                    sawIncompleteSurrogatePair)){                    fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,                                               "IllegalQName",                                               null,                                               XMLErrorReporter.SEVERITY_FATAL_ERROR);                }                localpart = fSymbolTable.addSymbol(fCurrentEntity.ch,                                                   index + 1, len);            }            else {                localpart = rawname;            }            qname.setValues(prefix, localpart, rawname, null);            return true;        }        return false;    } // scanQName(QName):boolean    /**     * Scans a range of parsed character data, setting the fields of the     * XMLString structure, appropriately.     * <p>     * <strong>Note:</strong> The characters are consumed.     * <p>     * <strong>Note:</strong> This method does not guarantee to return     * the longest run of parsed character data. This method may return     * before markup due to reaching the end of the input buffer or any     * other reason.     * <p>     * <strong>Note:</strong> The fields contained in the XMLString     * structure are not guaranteed to remain valid upon subsequent calls     * to the entity scanner. Therefore, the caller is responsible for     * immediately using the returned character data or making a copy of     * the character data.     *     * @param content The content structure to fill.     *     * @return Returns the next character on the input, if known. This     *         value may be -1 but this does <em>note</em> designate     *         end of file.     *     * @throws IOException  Thrown if i/o error occurs.     * @throws EOFException Thrown on end of file.     */    public int scanContent(XMLString content) throws IOException {        // load more characters, if needed        if (fCurrentEntity.position == fCurrentEntity.count) {            load(0, true);        }        else if (fCurrentEntity.position == fCurrentEntity.count - 1) {            fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];            load(1, false);            fCurrentEntity.position = 0;            fCurrentEntity.startPosition = 0;        }        // normalize newlines        int offset = fCurrentEntity.position;        int c = fCurrentEntity.ch[offset];        int newlines = 0;        boolean external = fCurrentEntity.isExternal();        if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {            do {                c = fCurrentEntity.ch[fCurrentEntity.position++];                if ((c == '\r' ) && external) {                    newlines++;                    fCurrentEntity.lineNumber++;                    fCurrentEntity.columnNumber = 1;                    if (fCurrentEntity.position == fCurrentEntity.count) {                        offset = 0;                        fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);                        fCurrentEntity.position = newlines;                        fCurrentEntity.startPosition = newlines;                        if (load(newlines, false)) {                            break;                        }                    }                    int cc = fCurrentEntity.ch[fCurrentEntity.position];                     if (cc == '\n' || cc == 0x85) {                        fCurrentEntity.position++;                        offset++;                    }                    /*** NEWLINE NORMALIZATION ***/                    else {                        newlines++;                    }                }                else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) {                    newlines++;                    fCurrentEntity.lineNumber++;                    fCurrentEntity.columnNumber = 1;                    if (fCurrentEntity.position == fCurrentEntity.count) {                        offset = 0;                        fCurrentEntity.baseCharOffset += (fCurrentEntity.position - fCurrentEntity.startPosition);                        fCurrentEntity.position = newlines;                        fCurrentEntity.startPosition = newlines;                        if (load(newlines, false)) {                            break;                        }                    }                }                else {                    fCurrentEntity.position--;                    break;                }            } while (fCurrentEntity.position < fCurrentEntity.count - 1);            for (int i = offset; i < fCurrentEntity.position; i++) {                fCurrentEntity.ch[i] = '\n';            }            int length = fCurrentEntity.position - offset;            if (fCurrentEntity.position == fCurrentEntity.count - 1) {                content.setValues(fCurrentEntity.ch, offset, length);                return -1;            }        }        // inner loop, scanning for content        if (external) {            while (fCurrentEntity.position < fCurrentEntity.count) {                c = fCurrentEntity.ch[fCurrentEntity.position++];                if (!XML11Char.isXML11Content(c) || c == 0x85 || c == 0x2028) {                    fCurrentEntity.position--;                    break;                }            }        }        else {            while (fCurrentEntity.position < fCurrentEntity.count) {                c = fCurrentEntity.ch[fCurrentEntity.position++];                // In internal entities control characters are allowed to appear unescaped.                if (!XML11Char.isXML11InternalEntityContent(c)) {                    fCurrentEntity.position--;                    break;                }            }        }        int length = fCurrentEntity.position - offset;        fCurrentEntity.columnNumber += length - newlines;        content.setValues(fCurrentEntity.ch, offset, length);        // return next character        if (fCurrentEntity.position != fCurrentEntity.count) {            c = fCurrentEntity.ch[fCurrentEntity.position];

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?