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


Java RegExpMatcher类代码示例

本文整理汇总了Java中jdk.nashorn.internal.runtime.regexp.RegExpMatcher的典型用法代码示例。如果您正苦于以下问题:Java RegExpMatcher类的具体用法?Java RegExpMatcher怎么用?Java RegExpMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RegExpMatcher类属于jdk.nashorn.internal.runtime.regexp包,在下文中一共展示了RegExpMatcher类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMatcher

import jdk.nashorn.internal.runtime.regexp.RegExpMatcher; //导入依赖的package包/类
/**
 * Compile a regular expression using the JDK implementation
 */
@Test
public void testMatcher() {
    final RegExp regexp = new RegExpFactory().compile("f(o)o", "");
    final RegExpMatcher matcher = regexp.match("foo");
    assertNotNull(matcher);
    assertTrue(matcher.search(0));
    assertEquals(matcher.getInput(), "foo");
    assertEquals(matcher.groupCount(), 1);
    assertEquals(matcher.group(), "foo");
    assertEquals(matcher.start(), 0);
    assertEquals(matcher.end(), 3);
    assertEquals(matcher.group(1), "o");
    assertEquals(matcher.start(1), 1);
    assertEquals(matcher.end(1), 2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:JdkRegExpTest.java

示例2: callReplaceValue

import jdk.nashorn.internal.runtime.regexp.RegExpMatcher; //导入依赖的package包/类
private String callReplaceValue(final MethodHandle invoker, final ScriptFunction function, final Object self, final RegExpMatcher matcher, final String string) throws Throwable {
    final Object[] groups = groups(matcher);
    final Object[] args   = Arrays.copyOf(groups, groups.length + 2);

    args[groups.length]     = matcher.start();
    args[groups.length + 1] = string;

    return (String)invoker.invokeExact(function, self, args);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:NativeRegExp.java

示例3: callReplaceValue

import jdk.nashorn.internal.runtime.regexp.RegExpMatcher; //导入依赖的package包/类
private String callReplaceValue(final MethodHandle invoker, final Object function, final Object self, final RegExpMatcher matcher, final String string) throws Throwable {
    final Object[] groups = groups(matcher);
    final Object[] args   = Arrays.copyOf(groups, groups.length + 2);

    args[groups.length]     = matcher.start();
    args[groups.length + 1] = string;

    return (String)invoker.invokeExact(function, self, args);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:NativeRegExp.java

示例4: callReplaceValue

import jdk.nashorn.internal.runtime.regexp.RegExpMatcher; //导入依赖的package包/类
private String callReplaceValue(final ScriptFunction function, final RegExpMatcher matcher, final String string) {
    final Object[] groups = groups(matcher);
    final Object[] args   = Arrays.copyOf(groups, groups.length + 2);

    args[groups.length]     = matcher.start();
    args[groups.length + 1] = string;

    final Object self = function.isStrict() ? UNDEFINED : Global.instance();

    return JSType.toString(ScriptRuntime.apply(function, self, args));
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:12,代码来源:NativeRegExp.java

示例5: appendReplacement

import jdk.nashorn.internal.runtime.regexp.RegExpMatcher; //导入依赖的package包/类
private void appendReplacement(final RegExpMatcher matcher, final String text, final String replacement, final StringBuilder sb) {
    /*
     * Process substitution patterns:
     *
     * $$ -> $
     * $& -> the matched substring
     * $` -> the portion of string that preceeds matched substring
     * $' -> the portion of string that follows the matched substring
     * $n -> the nth capture, where n is [1-9] and $n is NOT followed by a decimal digit
     * $nn -> the nnth capture, where nn is a two digit decimal number [01-99].
     */

    int cursor = 0;
    Object[] groups = null;

    while (cursor < replacement.length()) {
        char nextChar = replacement.charAt(cursor);
        if (nextChar == '$') {
            // Skip past $
            cursor++;
            if (cursor == replacement.length()) {
                // nothing after "$"
                sb.append('$');
                break;
            }

            nextChar = replacement.charAt(cursor);
            final int firstDigit = nextChar - '0';

            if (firstDigit >= 0 && firstDigit <= 9 && firstDigit <= matcher.groupCount()) {
                // $0 is not supported, but $01 is. implementation-defined: if n>m, ignore second digit.
                int refNum = firstDigit;
                cursor++;
                if (cursor < replacement.length() && firstDigit < matcher.groupCount()) {
                    final int secondDigit = replacement.charAt(cursor) - '0';
                    if (secondDigit >= 0 && secondDigit <= 9) {
                        final int newRefNum = firstDigit * 10 + secondDigit;
                        if (newRefNum <= matcher.groupCount() && newRefNum > 0) {
                            // $nn ($01-$99)
                            refNum = newRefNum;
                            cursor++;
                        }
                    }
                }
                if (refNum > 0) {
                    if (groups == null) {
                        groups = groups(matcher);
                    }
                    // Append group if matched.
                    if (groups[refNum] != UNDEFINED) {
                        sb.append((String) groups[refNum]);
                    }
                } else { // $0. ignore.
                    assert refNum == 0;
                    sb.append("$0");
                }
            } else if (nextChar == '$') {
                sb.append('$');
                cursor++;
            } else if (nextChar == '&') {
                sb.append(matcher.group());
                cursor++;
            } else if (nextChar == '`') {
                sb.append(text, 0, matcher.start());
                cursor++;
            } else if (nextChar == '\'') {
                sb.append(text, matcher.end(), text.length());
                cursor++;
            } else {
                // unknown substitution or $n with n>m. skip.
                sb.append('$');
            }
        } else {
            sb.append(nextChar);
            cursor++;
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:79,代码来源:NativeRegExp.java

示例6: appendReplacement

import jdk.nashorn.internal.runtime.regexp.RegExpMatcher; //导入依赖的package包/类
private void appendReplacement(final RegExpMatcher matcher, final String text, final String replacement, final StringBuilder sb) {
    /*
     * Process substitution patterns:
     *
     * $$ -> $
     * $& -> the matched substring
     * $` -> the portion of string that precedes matched substring
     * $' -> the portion of string that follows the matched substring
     * $n -> the nth capture, where n is [1-9] and $n is NOT followed by a decimal digit
     * $nn -> the nnth capture, where nn is a two digit decimal number [01-99].
     */

    int cursor = 0;
    Object[] groups = null;

    while (cursor < replacement.length()) {
        char nextChar = replacement.charAt(cursor);
        if (nextChar == '$') {
            // Skip past $
            cursor++;
            if (cursor == replacement.length()) {
                // nothing after "$"
                sb.append('$');
                break;
            }

            nextChar = replacement.charAt(cursor);
            final int firstDigit = nextChar - '0';

            if (firstDigit >= 0 && firstDigit <= 9 && firstDigit <= matcher.groupCount()) {
                // $0 is not supported, but $01 is. implementation-defined: if n>m, ignore second digit.
                int refNum = firstDigit;
                cursor++;
                if (cursor < replacement.length() && firstDigit < matcher.groupCount()) {
                    final int secondDigit = replacement.charAt(cursor) - '0';
                    if (secondDigit >= 0 && secondDigit <= 9) {
                        final int newRefNum = firstDigit * 10 + secondDigit;
                        if (newRefNum <= matcher.groupCount() && newRefNum > 0) {
                            // $nn ($01-$99)
                            refNum = newRefNum;
                            cursor++;
                        }
                    }
                }
                if (refNum > 0) {
                    if (groups == null) {
                        groups = groups(matcher);
                    }
                    // Append group if matched.
                    if (groups[refNum] != UNDEFINED) {
                        sb.append((String) groups[refNum]);
                    }
                } else { // $0. ignore.
                    assert refNum == 0;
                    sb.append("$0");
                }
            } else if (nextChar == '$') {
                sb.append('$');
                cursor++;
            } else if (nextChar == '&') {
                sb.append(matcher.group());
                cursor++;
            } else if (nextChar == '`') {
                sb.append(text, 0, matcher.start());
                cursor++;
            } else if (nextChar == '\'') {
                sb.append(text, matcher.end(), text.length());
                cursor++;
            } else {
                // unknown substitution or $n with n>m. skip.
                sb.append('$');
            }
        } else {
            sb.append(nextChar);
            cursor++;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:79,代码来源:NativeRegExp.java

示例7: appendReplacement

import jdk.nashorn.internal.runtime.regexp.RegExpMatcher; //导入依赖的package包/类
private void appendReplacement(final RegExpMatcher matcher, final String text, final String replacement, final StringBuilder sb) {
    /*
     * Process substitution patterns:
     *
     * $$ -> $
     * $& -> the matched substring
     * $` -> the portion of string that preceeds matched substring
     * $' -> the portion of string that follows the matched substring
     * $n -> the nth capture, where n is [1-9] and $n is NOT followed by a decimal digit
     * $nn -> the nnth capture, where nn is a two digit decimal number [01-99].
     */

    int cursor = 0;
    Object[] groups = null;

    while (cursor < replacement.length()) {
        char nextChar = replacement.charAt(cursor);
        if (nextChar == '$') {
            // Skip past $
            cursor++;
            nextChar = replacement.charAt(cursor);
            final int firstDigit = nextChar - '0';

            if (firstDigit >= 0 && firstDigit <= 9 && firstDigit <= matcher.groupCount()) {
                // $0 is not supported, but $01 is. implementation-defined: if n>m, ignore second digit.
                int refNum = firstDigit;
                cursor++;
                if (cursor < replacement.length() && firstDigit < matcher.groupCount()) {
                    final int secondDigit = replacement.charAt(cursor) - '0';
                    if ((secondDigit >= 0) && (secondDigit <= 9)) {
                        final int newRefNum = (firstDigit * 10) + secondDigit;
                        if (newRefNum <= matcher.groupCount() && newRefNum > 0) {
                            // $nn ($01-$99)
                            refNum = newRefNum;
                            cursor++;
                        }
                    }
                }
                if (refNum > 0) {
                    if (groups == null) {
                        groups = groups(matcher);
                    }
                    // Append group if matched.
                    if (groups[refNum] != UNDEFINED) {
                        sb.append((String) groups[refNum]);
                    }
                } else { // $0. ignore.
                    assert refNum == 0;
                    sb.append("$0");
                }
            } else if (nextChar == '$') {
                sb.append('$');
                cursor++;
            } else if (nextChar == '&') {
                sb.append(matcher.group());
                cursor++;
            } else if (nextChar == '`') {
                sb.append(text, 0, matcher.start());
                cursor++;
            } else if (nextChar == '\'') {
                sb.append(text, matcher.end(), text.length());
                cursor++;
            } else {
                // unknown substitution or $n with n>m. skip.
                sb.append('$');
            }
        } else {
            sb.append(nextChar);
            cursor++;
        }
    }
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:73,代码来源:NativeRegExp.java


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