Java Code Examples for jdk.nashorn.internal.runtime.regexp.joni.encoding.CharacterType#SPECIAL_MASK

The following examples show how to use jdk.nashorn.internal.runtime.regexp.joni.encoding.CharacterType#SPECIAL_MASK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CClassNode.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public void addCType(int ctype, boolean not, ScanEnvironment env, IntHolder sbOut) {
    if (Config.NON_UNICODE_SDW) {
        switch(ctype) {
        case CharacterType.D:
        case CharacterType.S:
        case CharacterType.W:
            ctype ^= CharacterType.SPECIAL_MASK;

            if (env.syntax == Syntax.JAVASCRIPT && ctype == CharacterType.SPACE) {
                // \s in JavaScript includes unicode characters.
                break;
            }

            if (not) {
                for (int c = 0; c < BitSet.SINGLE_BYTE_SIZE; c++) {
                    // if (!ASCIIEncoding.INSTANCE.isCodeCType(c, ctype)) bs.set(c);
                    if ((AsciiCtypeTable[c] & (1 << ctype)) == 0) bs.set(c);
                }
                addAllMultiByteRange();
            } else {
                for (int c = 0; c < BitSet.SINGLE_BYTE_SIZE; c++) {
                    // if (ASCIIEncoding.INSTANCE.isCodeCType(c, ctype)) bs.set(c);
                    if ((AsciiCtypeTable[c] & (1 << ctype)) != 0) bs.set(c);
                }
            }
            return;
        }
    }

    int[] ranges = EncodingHelper.ctypeCodeRange(ctype, sbOut);
    if (ranges != null) {
        addCTypeByRange(ctype, not, sbOut.value, ranges);
        return;
    }

    switch(ctype) {
    case CharacterType.ALPHA:
    case CharacterType.BLANK:
    case CharacterType.CNTRL:
    case CharacterType.DIGIT:
    case CharacterType.LOWER:
    case CharacterType.PUNCT:
    case CharacterType.SPACE:
    case CharacterType.UPPER:
    case CharacterType.XDIGIT:
    case CharacterType.ASCII:
    case CharacterType.ALNUM:
        if (not) {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (!EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
            addAllMultiByteRange();
        } else {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
        }
        break;

    case CharacterType.GRAPH:
    case CharacterType.PRINT:
        if (not) {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (!EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
        } else {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
            addAllMultiByteRange();
        }
        break;

    case CharacterType.WORD:
        if (!not) {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (EncodingHelper.isWord(c)) bs.set(c);
            }

            addAllMultiByteRange();
        } else {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (!EncodingHelper.isWord(c)) bs.set(c);
            }
        }
        break;

    default:
        throw new InternalException(ErrorMessages.ERR_PARSER_BUG);
    } // switch
}
 
Example 2
Source File: CClassNode.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void addCType(int ctype, boolean not, ScanEnvironment env, IntHolder sbOut) {
    if (Config.NON_UNICODE_SDW) {
        switch(ctype) {
        case CharacterType.D:
        case CharacterType.S:
        case CharacterType.W:
            ctype ^= CharacterType.SPECIAL_MASK;

            if (env.syntax == Syntax.JAVASCRIPT && ctype == CharacterType.SPACE) {
                // \s in JavaScript includes unicode characters.
                break;
            }

            if (not) {
                for (int c = 0; c < BitSet.SINGLE_BYTE_SIZE; c++) {
                    // if (!ASCIIEncoding.INSTANCE.isCodeCType(c, ctype)) bs.set(c);
                    if ((AsciiCtypeTable[c] & (1 << ctype)) == 0) bs.set(c);
                }
                addAllMultiByteRange();
            } else {
                for (int c = 0; c < BitSet.SINGLE_BYTE_SIZE; c++) {
                    // if (ASCIIEncoding.INSTANCE.isCodeCType(c, ctype)) bs.set(c);
                    if ((AsciiCtypeTable[c] & (1 << ctype)) != 0) bs.set(c);
                }
            }
            return;
        }
    }

    int[] ranges = EncodingHelper.ctypeCodeRange(ctype, sbOut);
    if (ranges != null) {
        addCTypeByRange(ctype, not, sbOut.value, ranges);
        return;
    }

    switch(ctype) {
    case CharacterType.ALPHA:
    case CharacterType.BLANK:
    case CharacterType.CNTRL:
    case CharacterType.DIGIT:
    case CharacterType.LOWER:
    case CharacterType.PUNCT:
    case CharacterType.SPACE:
    case CharacterType.UPPER:
    case CharacterType.XDIGIT:
    case CharacterType.ASCII:
    case CharacterType.ALNUM:
        if (not) {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (!EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
            addAllMultiByteRange();
        } else {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
        }
        break;

    case CharacterType.GRAPH:
    case CharacterType.PRINT:
        if (not) {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (!EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
        } else {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
            addAllMultiByteRange();
        }
        break;

    case CharacterType.WORD:
        if (!not) {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (EncodingHelper.isWord(c)) bs.set(c);
            }

            addAllMultiByteRange();
        } else {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (!EncodingHelper.isWord(c)) bs.set(c);
            }
        }
        break;

    default:
        throw new InternalException(ErrorMessages.ERR_PARSER_BUG);
    } // switch
}
 
Example 3
Source File: CClassNode.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
public void addCType(int ctype, boolean not, ScanEnvironment env, IntHolder sbOut) {
    if (Config.NON_UNICODE_SDW) {
        switch(ctype) {
        case CharacterType.D:
        case CharacterType.S:
        case CharacterType.W:
            ctype ^= CharacterType.SPECIAL_MASK;

            if (env.syntax == Syntax.JAVASCRIPT && ctype == CharacterType.SPACE) {
                // \s in JavaScript includes unicode characters.
                break;
            }

            if (not) {
                for (int c = 0; c < BitSet.SINGLE_BYTE_SIZE; c++) {
                    // if (!ASCIIEncoding.INSTANCE.isCodeCType(c, ctype)) bs.set(c);
                    if ((AsciiCtypeTable[c] & (1 << ctype)) == 0) bs.set(c);
                }
                addAllMultiByteRange();
            } else {
                for (int c = 0; c < BitSet.SINGLE_BYTE_SIZE; c++) {
                    // if (ASCIIEncoding.INSTANCE.isCodeCType(c, ctype)) bs.set(c);
                    if ((AsciiCtypeTable[c] & (1 << ctype)) != 0) bs.set(c);
                }
            }
            return;
        }
    }

    int[] ranges = EncodingHelper.ctypeCodeRange(ctype, sbOut);
    if (ranges != null) {
        addCTypeByRange(ctype, not, sbOut.value, ranges);
        return;
    }

    switch(ctype) {
    case CharacterType.ALPHA:
    case CharacterType.BLANK:
    case CharacterType.CNTRL:
    case CharacterType.DIGIT:
    case CharacterType.LOWER:
    case CharacterType.PUNCT:
    case CharacterType.SPACE:
    case CharacterType.UPPER:
    case CharacterType.XDIGIT:
    case CharacterType.ASCII:
    case CharacterType.ALNUM:
        if (not) {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (!EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
            addAllMultiByteRange();
        } else {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
        }
        break;

    case CharacterType.GRAPH:
    case CharacterType.PRINT:
        if (not) {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (!EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
        } else {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (EncodingHelper.isCodeCType(c, ctype)) bs.set(c);
            }
            addAllMultiByteRange();
        }
        break;

    case CharacterType.WORD:
        if (!not) {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (EncodingHelper.isWord(c)) bs.set(c);
            }

            addAllMultiByteRange();
        } else {
            for (int c=0; c<BitSet.SINGLE_BYTE_SIZE; c++) {
                if (!EncodingHelper.isWord(c)) bs.set(c);
            }
        }
        break;

    default:
        throw new InternalException(ErrorMessages.ERR_PARSER_BUG);
    } // switch
}