当前位置: 首页>>代码示例>>Java>>正文


Java Entities.isNamedEntity方法代码示例

本文整理汇总了Java中org.jsoup.nodes.Entities.isNamedEntity方法的典型用法代码示例。如果您正苦于以下问题:Java Entities.isNamedEntity方法的具体用法?Java Entities.isNamedEntity怎么用?Java Entities.isNamedEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jsoup.nodes.Entities的用法示例。


在下文中一共展示了Entities.isNamedEntity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: consumeCharacterReference

import org.jsoup.nodes.Entities; //导入方法依赖的package包/类
char[] consumeCharacterReference(Character additionalAllowedCharacter, boolean inAttribute) {
    if (reader.isEmpty())
        return null;
    if (additionalAllowedCharacter != null && additionalAllowedCharacter == reader.current())
        return null;
    if (reader.matchesAnySorted(notCharRefCharsSorted))
        return null;

    final char[] charRef = charRefHolder;
    reader.mark();
    if (reader.matchConsume("#")) { // numbered
        boolean isHexMode = reader.matchConsumeIgnoreCase("X");
        String numRef = isHexMode ? reader.consumeHexSequence() : reader.consumeDigitSequence();
        if (numRef.length() == 0) { // didn't match anything
            characterReferenceError("numeric reference with no numerals");
            reader.rewindToMark();
            return null;
        }
        if (!reader.matchConsume(";"))
            characterReferenceError("missing semicolon"); // missing semi
        int charval = -1;
        try {
            int base = isHexMode ? 16 : 10;
            charval = Integer.valueOf(numRef, base);
        } catch (NumberFormatException e) {
        } // skip
        if (charval == -1 || (charval >= 0xD800 && charval <= 0xDFFF) || charval > 0x10FFFF) {
            characterReferenceError("character outside of valid range");
            charRef[0] = replacementChar;
            return charRef;
        } else {
            // todo: implement number replacement table
            // todo: check for extra illegal unicode points as parse errors
            if (charval < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
                charRef[0] = (char) charval;
                return charRef;
            } else
            return Character.toChars(charval);
        }
    } else { // named
        // get as many letters as possible, and look for matching entities.
        String nameRef = reader.consumeLetterThenDigitSequence();
        boolean looksLegit = reader.matches(';');
        // found if a base named entity without a ;, or an extended entity with the ;.
        boolean found = (Entities.isBaseNamedEntity(nameRef) || (Entities.isNamedEntity(nameRef) && looksLegit));

        if (!found) {
            reader.rewindToMark();
            if (looksLegit) // named with semicolon
                characterReferenceError(String.format("invalid named referenece '%s'", nameRef));
            return null;
        }
        if (inAttribute && (reader.matchesLetter() || reader.matchesDigit() || reader.matchesAny('=', '-', '_'))) {
            // don't want that to match
            reader.rewindToMark();
            return null;
        }
        if (!reader.matchConsume(";"))
            characterReferenceError("missing semicolon"); // missing semi
        charRef[0] = Entities.getCharacterByName(nameRef);
        return charRef;
    }
}
 
开发者ID:cpusoft,项目名称:common,代码行数:64,代码来源:Tokeniser.java

示例2: consumeCharacterReference

import org.jsoup.nodes.Entities; //导入方法依赖的package包/类
char[] consumeCharacterReference(Character additionalAllowedCharacter, boolean inAttribute) {
    if (reader.isEmpty())
        return null;
    if (additionalAllowedCharacter != null && additionalAllowedCharacter == reader.current())
        return null;
    if (reader.matchesAny('\t', '\n', '\r', '\f', ' ', '<', '&'))
        return null;

    reader.mark();
    if (reader.matchConsume("#")) { // numbered
        boolean isHexMode = reader.matchConsumeIgnoreCase("X");
        String numRef = isHexMode ? reader.consumeHexSequence() : reader.consumeDigitSequence();
        if (numRef.length() == 0) { // didn't match anything
            characterReferenceError("numeric reference with no numerals");
            reader.rewindToMark();
            return null;
        }
        if (!reader.matchConsume(";"))
            characterReferenceError("missing semicolon"); // missing semi
        int charval = -1;
        try {
            int base = isHexMode ? 16 : 10;
            charval = Integer.valueOf(numRef, base);
        } catch (NumberFormatException e) {
        } // skip
        if (charval == -1 || (charval >= 0xD800 && charval <= 0xDFFF) || charval > 0x10FFFF) {
            characterReferenceError("character outside of valid range");
            return new char[]{replacementChar};
        } else {
            // todo: implement number replacement table
            // todo: check for extra illegal unicode points as parse errors
            return Character.toChars(charval);
        }
    } else { // named
        // get as many letters as possible, and look for matching entities.
        String nameRef = reader.consumeLetterThenDigitSequence();
        boolean looksLegit = reader.matches(';');
        // found if a base named entity without a ;, or an extended entity with the ;.
        boolean found = (Entities.isBaseNamedEntity(nameRef) || (Entities.isNamedEntity(nameRef) && looksLegit));

        if (!found) {
            reader.rewindToMark();
            if (looksLegit) // named with semicolon
                characterReferenceError(String.format("invalid named referenece '%s'", nameRef));
            return null;
        }
        if (inAttribute && (reader.matchesLetter() || reader.matchesDigit() || reader.matchesAny('=', '-', '_'))) {
            // don't want that to match
            reader.rewindToMark();
            return null;
        }
        if (!reader.matchConsume(";"))
            characterReferenceError("missing semicolon"); // missing semi
        return new char[]{Entities.getCharacterByName(nameRef)};
    }
}
 
开发者ID:shannah,项目名称:CN1ML-NetbeansModule,代码行数:57,代码来源:Tokeniser.java

示例3: consumeCharacterReference

import org.jsoup.nodes.Entities; //导入方法依赖的package包/类
int[] consumeCharacterReference(Character additionalAllowedCharacter, boolean inAttribute) {
    if (reader.isEmpty())
        return null;
    if (additionalAllowedCharacter != null && additionalAllowedCharacter == reader.current())
        return null;
    if (reader.matchesAnySorted(notCharRefCharsSorted))
        return null;

    final int[] codeRef = codepointHolder;
    reader.mark();
    if (reader.matchConsume("#")) { // numbered
        boolean isHexMode = reader.matchConsumeIgnoreCase("X");
        String numRef = isHexMode ? reader.consumeHexSequence() : reader.consumeDigitSequence();
        if (numRef.length() == 0) { // didn't match anything
            characterReferenceError("numeric reference with no numerals");
            reader.rewindToMark();
            return null;
        }
        if (!reader.matchConsume(";"))
            characterReferenceError("missing semicolon"); // missing semi
        int charval = -1;
        try {
            int base = isHexMode ? 16 : 10;
            charval = Integer.valueOf(numRef, base);
        } catch (NumberFormatException ignored) {
        } // skip
        if (charval == -1 || (charval >= 0xD800 && charval <= 0xDFFF) || charval > 0x10FFFF) {
            characterReferenceError("character outside of valid range");
            codeRef[0] = replacementChar;
            return codeRef;
        } else {
            // todo: implement number replacement table
            // todo: check for extra illegal unicode points as parse errors
            codeRef[0] = charval;
            return codeRef;
        }
    } else { // named
        // get as many letters as possible, and look for matching entities.
        String nameRef = reader.consumeLetterThenDigitSequence();
        boolean looksLegit = reader.matches(';');
        // found if a base named entity without a ;, or an extended entity with the ;.
        boolean found = (Entities.isBaseNamedEntity(nameRef) || (Entities.isNamedEntity(nameRef) && looksLegit));

        if (!found) {
            reader.rewindToMark();
            if (looksLegit) // named with semicolon
                characterReferenceError(String.format("invalid named referenece '%s'", nameRef));
            return null;
        }
        if (inAttribute && (reader.matchesLetter() || reader.matchesDigit() || reader.matchesAny('=', '-', '_'))) {
            // don't want that to match
            reader.rewindToMark();
            return null;
        }
        if (!reader.matchConsume(";"))
            characterReferenceError("missing semicolon"); // missing semi
        int numChars = Entities.codepointsForName(nameRef, multipointHolder);
        if (numChars == 1) {
            codeRef[0] = multipointHolder[0];
            return codeRef;
        } else if (numChars ==2) {
            return multipointHolder;
        } else {
            Validate.fail("Unexpected characters returned for " + nameRef);
            return multipointHolder;
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:69,代码来源:Tokeniser.java

示例4: consumeCharacterReference

import org.jsoup.nodes.Entities; //导入方法依赖的package包/类
Character consumeCharacterReference(Character additionalAllowedCharacter, boolean inAttribute) {
    if (reader.isEmpty())
        return null;
    if (additionalAllowedCharacter != null && additionalAllowedCharacter == reader.current())
        return null;
    if (reader.matchesAny('\t', '\n', '\f', '<', '&'))
        return null;

    reader.mark();
    if (reader.matchConsume("#")) { // numbered
        boolean isHexMode = reader.matchConsumeIgnoreCase("X");
        String numRef = isHexMode ? reader.consumeHexSequence() : reader.consumeDigitSequence();
        if (numRef.length() == 0) { // didn't match anything
            characterReferenceError();
            reader.rewindToMark();
            return null;
        }
        if (!reader.matchConsume(";"))
            characterReferenceError(); // missing semi
        int charval = -1;
        try {
            int base = isHexMode ? 16 : 10;
            charval = Integer.valueOf(numRef, base);
        } catch (NumberFormatException e) {
        } // skip
        if (charval == -1 || (charval >= 0xD800 && charval <= 0xDFFF) || charval > 0x10FFFF) {
            characterReferenceError();
            return replacementChar;
        } else {
            // todo: implement number replacement table
            // todo: check for extra illegal unicode points as parse errors
            return (char) charval;
        }
    } else { // named
        // get as many letters as possible, and look for matching entities. unconsume backwards till a match is found
        String nameRef = reader.consumeLetterSequence();
        boolean looksLegit = reader.matches(';');
        boolean found = false;
        while (nameRef.length() > 0 && !found) {
            if (Entities.isNamedEntity(nameRef))
                found = true;
            else {
                nameRef = nameRef.substring(0, nameRef.length()-1);
                reader.unconsume();
            }
        }
        if (!found) {
            if (looksLegit) // named with semicolon
                characterReferenceError();
            reader.rewindToMark();
            return null;
        }
        if (inAttribute && (reader.matchesLetter() || reader.matchesDigit() || reader.matches('='))) {
            // don't want that to match
            reader.rewindToMark();
            return null;
        }
        if (!reader.matchConsume(";"))
            characterReferenceError(); // missing semi
        return Entities.getCharacterByName(nameRef);
    }
}
 
开发者ID:gumulka,项目名称:JabRefAutocomplete,代码行数:63,代码来源:Tokeniser.java


注:本文中的org.jsoup.nodes.Entities.isNamedEntity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。