Java Code Examples for jdk.nashorn.internal.runtime.regexp.joni.ast.StringNode#cat()

The following examples show how to use jdk.nashorn.internal.runtime.regexp.joni.ast.StringNode#cat() . 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: Parser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseExpTkByte(final boolean group) {
    final StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) {
            break;
        }

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 2
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseExpTkByte(final boolean group) {
    final StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) {
            break;
        }

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 3
Source File: Parser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Node parseExpTkByte(final boolean group) {
    final StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) {
            break;
        }

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 4
Source File: Parser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private Node parseExpTkByte(final boolean group) {
    final StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) {
            break;
        }

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 5
Source File: Parser.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private Node parseExpTkByte(final boolean group) {
    final StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) {
            break;
        }

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 6
Source File: Parser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private Node parseExpTkByte(final boolean group) {
    final StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) {
            break;
        }

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 7
Source File: Parser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private Node parseExpTkByte(final boolean group) {
    final StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) {
            break;
        }

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 8
Source File: Parser.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpTkByte(boolean group) {
    StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) break;

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 9
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpTkByte(boolean group) {
    StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) break;

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 10
Source File: Parser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private Node parseExpTkByte(boolean group) {
    StringNode node = new StringNode(chars, token.backP, p); // tk_byte:
    while (true) {
        fetchToken();
        if (token.type != TokenType.STRING) break;

        if (token.backP == node.end) {
            node.end = p; // non escaped character, remain shared, just increase shared range
        } else {
            node.cat(chars, token.backP, p); // non continuous string stream, need to COW
        }
    }
    // targetp = node;
    return parseExpRepeat(node, group); // string_end:, goto repeat
}
 
Example 11
Source File: Analyser.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(Node node) {
    StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) return node;

    char[] chars = sn.chars;
    int p = sn.p;
    int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, root = null;
    ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (p < end) {
        char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars[p]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (root == null && prevNode.p != null) {
                    topRoot = root = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (root != null) ConsAltNode.listAdd(root, stringNode);

            }

            stringNode.cat(chars, p, p + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) break;

            if (root == null && prevNode.p != null) {
                topRoot = root = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars, p, 1, end, prevNode);
            if (root != null) ConsAltNode.listAdd(root, prevNode.p);
            stringNode = null;
        }
        p++;
    }

    if (p < end) {
        Node srem = expandCaseFoldMakeRemString(chars, p, end);

        if (prevNode.p != null && root == null) {
            topRoot = root = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (root == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(root, srem);
        }
    }
    /* ending */
    Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}
 
Example 12
Source File: Analyser.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(final Node node) {
    final StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) {
        return node;
    }

    final char[] chars1 = sn.chars;
    int pt = sn.p;
    final int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, r = null;
    @SuppressWarnings("unused")
    final ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (pt < end) {
        final char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars1[pt]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (r == null && prevNode.p != null) {
                    topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (r != null) {
                    ConsAltNode.listAdd(r, stringNode);
                }

            }

            stringNode.cat(chars1, pt, pt + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) {
                break;
            }

            if (r == null && prevNode.p != null) {
                topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars1, pt, 1, end, prevNode);
            if (r != null) {
                ConsAltNode.listAdd(r, prevNode.p);
            }
            stringNode = null;
        }
        pt++;
    }

    if (pt < end) {
        final Node srem = expandCaseFoldMakeRemString(chars1, pt, end);

        if (prevNode.p != null && r == null) {
            topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (r == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(r, srem);
        }
    }
    /* ending */
    final Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}
 
Example 13
Source File: Analyser.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(Node node) {
    StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) return node;

    char[] chars = sn.chars;
    int p = sn.p;
    int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, root = null;
    ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (p < end) {
        char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars[p]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (root == null && prevNode.p != null) {
                    topRoot = root = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (root != null) ConsAltNode.listAdd(root, stringNode);

            }

            stringNode.cat(chars, p, p + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) break;

            if (root == null && prevNode.p != null) {
                topRoot = root = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars, p, 1, end, prevNode);
            if (root != null) ConsAltNode.listAdd(root, prevNode.p);
            stringNode = null;
        }
        p++;
    }

    if (p < end) {
        Node srem = expandCaseFoldMakeRemString(chars, p, end);

        if (prevNode.p != null && root == null) {
            topRoot = root = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (root == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(root, srem);
        }
    }
    /* ending */
    Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}
 
Example 14
Source File: Analyser.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(Node node) {
    StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) return node;

    char[] chars = sn.chars;
    int p = sn.p;
    int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, root = null;
    ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (p < end) {
        char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars[p]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (root == null && prevNode.p != null) {
                    topRoot = root = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (root != null) ConsAltNode.listAdd(root, stringNode);

            }

            stringNode.cat(chars, p, p + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) break;

            if (root == null && prevNode.p != null) {
                topRoot = root = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars, p, 1, end, prevNode);
            if (root != null) ConsAltNode.listAdd(root, prevNode.p);
            stringNode = null;
        }
        p++;
    }

    if (p < end) {
        Node srem = expandCaseFoldMakeRemString(chars, p, end);

        if (prevNode.p != null && root == null) {
            topRoot = root = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (root == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(root, srem);
        }
    }
    /* ending */
    Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}
 
Example 15
Source File: Analyser.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(final Node node) {
    final StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) {
        return node;
    }

    final char[] chars1 = sn.chars;
    int pt = sn.p;
    final int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, r = null;
    @SuppressWarnings("unused")
    final ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (pt < end) {
        final char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars1[pt]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (r == null && prevNode.p != null) {
                    topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (r != null) {
                    ConsAltNode.listAdd(r, stringNode);
                }

            }

            stringNode.cat(chars1, pt, pt + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) {
                break;
            }

            if (r == null && prevNode.p != null) {
                topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars1, pt, 1, end, prevNode);
            if (r != null) {
                ConsAltNode.listAdd(r, prevNode.p);
            }
            stringNode = null;
        }
        pt++;
    }

    if (pt < end) {
        final Node srem = expandCaseFoldMakeRemString(chars1, pt, end);

        if (prevNode.p != null && r == null) {
            topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (r == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(r, srem);
        }
    }
    /* ending */
    final Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}
 
Example 16
Source File: Analyser.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(final Node node) {
    final StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) {
        return node;
    }

    final char[] chars1 = sn.chars;
    int pt = sn.p;
    final int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, r = null;
    @SuppressWarnings("unused")
    final ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (pt < end) {
        final char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars1[pt]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (r == null && prevNode.p != null) {
                    topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (r != null) {
                    ConsAltNode.listAdd(r, stringNode);
                }

            }

            stringNode.cat(chars1, pt, pt + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) {
                break;
            }

            if (r == null && prevNode.p != null) {
                topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars1, pt, 1, end, prevNode);
            if (r != null) {
                ConsAltNode.listAdd(r, prevNode.p);
            }
            stringNode = null;
        }
        pt++;
    }

    if (pt < end) {
        final Node srem = expandCaseFoldMakeRemString(chars1, pt, end);

        if (prevNode.p != null && r == null) {
            topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (r == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(r, srem);
        }
    }
    /* ending */
    final Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}
 
Example 17
Source File: Analyser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(final Node node) {
    final StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) {
        return node;
    }

    final char[] chars1 = sn.chars;
    int pt = sn.p;
    final int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, r = null;
    @SuppressWarnings("unused")
    final ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (pt < end) {
        final char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars1[pt]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (r == null && prevNode.p != null) {
                    topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (r != null) {
                    ConsAltNode.listAdd(r, stringNode);
                }

            }

            stringNode.cat(chars1, pt, pt + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) {
                break;
            }

            if (r == null && prevNode.p != null) {
                topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars1, pt, 1, end, prevNode);
            if (r != null) {
                ConsAltNode.listAdd(r, prevNode.p);
            }
            stringNode = null;
        }
        pt++;
    }

    if (pt < end) {
        final Node srem = expandCaseFoldMakeRemString(chars1, pt, end);

        if (prevNode.p != null && r == null) {
            topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (r == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(r, srem);
        }
    }
    /* ending */
    final Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}
 
Example 18
Source File: Analyser.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(final Node node) {
    final StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) {
        return node;
    }

    final char[] chars1 = sn.chars;
    int pt = sn.p;
    final int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, r = null;
    @SuppressWarnings("unused")
    final ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (pt < end) {
        final char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars1[pt]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (r == null && prevNode.p != null) {
                    topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (r != null) {
                    ConsAltNode.listAdd(r, stringNode);
                }

            }

            stringNode.cat(chars1, pt, pt + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) {
                break;
            }

            if (r == null && prevNode.p != null) {
                topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars1, pt, 1, end, prevNode);
            if (r != null) {
                ConsAltNode.listAdd(r, prevNode.p);
            }
            stringNode = null;
        }
        pt++;
    }

    if (pt < end) {
        final Node srem = expandCaseFoldMakeRemString(chars1, pt, end);

        if (prevNode.p != null && r == null) {
            topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (r == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(r, srem);
        }
    }
    /* ending */
    final Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}
 
Example 19
Source File: Analyser.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(final Node node) {
    final StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) {
        return node;
    }

    final char[] chars1 = sn.chars;
    int pt = sn.p;
    final int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, r = null;
    @SuppressWarnings("unused")
    final ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (pt < end) {
        final char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars1[pt]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (r == null && prevNode.p != null) {
                    topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (r != null) {
                    ConsAltNode.listAdd(r, stringNode);
                }

            }

            stringNode.cat(chars1, pt, pt + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) {
                break;
            }

            if (r == null && prevNode.p != null) {
                topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars1, pt, 1, end, prevNode);
            if (r != null) {
                ConsAltNode.listAdd(r, prevNode.p);
            }
            stringNode = null;
        }
        pt++;
    }

    if (pt < end) {
        final Node srem = expandCaseFoldMakeRemString(chars1, pt, end);

        if (prevNode.p != null && r == null) {
            topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (r == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(r, srem);
        }
    }
    /* ending */
    final Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}
 
Example 20
Source File: Analyser.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private Node expandCaseFoldString(final Node node) {
    final StringNode sn = (StringNode)node;

    if (sn.isAmbig() || sn.length() <= 0) {
        return node;
    }

    final char[] chars1 = sn.chars;
    int pt = sn.p;
    final int end = sn.end;
    int altNum = 1;

    ConsAltNode topRoot = null, r = null;
    @SuppressWarnings("unused")
    final ObjPtr<Node> prevNode = new ObjPtr<Node>();
    StringNode stringNode = null;

    while (pt < end) {
        final char[] items = EncodingHelper.caseFoldCodesByString(regex.caseFoldFlag, chars1[pt]);

        if (items.length == 0) {
            if (stringNode == null) {
                if (r == null && prevNode.p != null) {
                    topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
                }

                prevNode.p = stringNode = new StringNode(); // onig_node_new_str(NULL, NULL);

                if (r != null) {
                    ConsAltNode.listAdd(r, stringNode);
                }

            }

            stringNode.cat(chars1, pt, pt + 1);
        } else {
            altNum *= (items.length + 1);
            if (altNum > THRESHOLD_CASE_FOLD_ALT_FOR_EXPANSION) {
                break;
            }

            if (r == null && prevNode.p != null) {
                topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
            }

            expandCaseFoldStringAlt(items.length, items, chars1, pt, 1, end, prevNode);
            if (r != null) {
                ConsAltNode.listAdd(r, prevNode.p);
            }
            stringNode = null;
        }
        pt++;
    }

    if (pt < end) {
        final Node srem = expandCaseFoldMakeRemString(chars1, pt, end);

        if (prevNode.p != null && r == null) {
            topRoot = r = ConsAltNode.listAdd(null, prevNode.p);
        }

        if (r == null) {
            prevNode.p = srem;
        } else {
            ConsAltNode.listAdd(r, srem);
        }
    }
    /* ending */
    final Node xnode = topRoot != null ? topRoot : prevNode.p;

    swap(node, xnode);
    return xnode;
}