jdk.nashorn.internal.runtime.regexp.RegExpResult Java Examples

The following examples show how to use jdk.nashorn.internal.runtime.regexp.RegExpResult. 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: NativeRegExpExecResult.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
NativeRegExpExecResult(final RegExpResult result, final Global global) {
    super(global.getArrayPrototype(), $nasgenmap$);
    setIsArray();
    this.setArray(ArrayData.allocate(result.getGroups().clone()));
    this.index = result.getIndex();
    this.input = result.getInput();
}
 
Example #2
Source File: NativeRegExp.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Executes a search for a match within a string based on a regular
 * expression. It returns an array of information or null if no match is
 * found.
 *
 * @param string String to match.
 * @return NativeArray of matches, string or null.
 */
public Object exec(final String string) {
    final RegExpResult match = execInner(string);

    if (match == null) {
        return null;
    }

    return new NativeRegExpExecResult(match, globalObject);
}
 
Example #3
Source File: NativeRegExp.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests for a match in a string. It returns the index of the match, or -1
 * if not found.
 *
 * @param string String to match.
 * @return Index of match.
 */
Object search(final String string) {
    final RegExpResult match = execInner(string);

    if (match == null) {
        return -1;
    }

    return match.getIndex();
}
 
Example #4
Source File: NativeRegExp.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Executes a search for a match within a string based on a regular
 * expression. It returns an array of information or null if no match is
 * found.
 *
 * @param string String to match.
 * @return NativeArray of matches, string or null.
 */
public NativeRegExpExecResult exec(final String string) {
    final RegExpResult match = execInner(string);

    if (match == null) {
        return null;
    }

    return new NativeRegExpExecResult(match, globalObject);
}
 
Example #5
Source File: NativeRegExpExecResult.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
NativeRegExpExecResult(final RegExpResult result, final Global global) {
    super(global.getArrayPrototype(), $nasgenmap$);
    setIsArray();
    this.setArray(ArrayData.allocate(result.getGroups().clone()));
    this.index = result.getIndex();
    this.input = result.getInput();
}
 
Example #6
Source File: NativeRegExp.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests for a match in a string. It returns the index of the match, or -1
 * if not found.
 *
 * @param string String to match.
 * @return Index of match.
 */
int search(final String string) {
    final RegExpResult match = execInner(string);

    if (match == null) {
        return -1;
    }

    return match.getIndex();
}
 
Example #7
Source File: NativeRegExp.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Executes a search for a match within a string based on a regular
 * expression. It returns an array of information or null if no match is
 * found.
 *
 * @param string String to match.
 * @return NativeArray of matches, string or null.
 */
public NativeRegExpExecResult exec(final String string) {
    final RegExpResult match = execInner(string);

    if (match == null) {
        return null;
    }

    return new NativeRegExpExecResult(match, globalObject);
}
 
Example #8
Source File: NativeRegExp.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests for a match in a string. It returns the index of the match, or -1
 * if not found.
 *
 * @param string String to match.
 * @return Index of match.
 */
Object search(final String string) {
    final RegExpResult match = execInner(string);

    if (match == null) {
        return -1;
    }

    return match.getIndex();
}
 
Example #9
Source File: NativeRegExpExecResult.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
NativeRegExpExecResult(final RegExpResult result, final Global global) {
    super(global.getArrayPrototype(), global.getRegExpExecResultMap());
    setIsArray();
    this.setArray(ArrayData.allocate(result.getGroups().clone()));
    this.index = result.getIndex();
    this.input = result.getInput();
}
 
Example #10
Source File: NativeRegExpExecResult.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
NativeRegExpExecResult(final RegExpResult result, final Global global) {
    super(global.getArrayPrototype(), $nasgenmap$);
    setIsArray();
    this.setArray(ArrayData.allocate(result.getGroups().clone()));
    this.index = result.getIndex();
    this.input = result.getInput();
}
 
Example #11
Source File: NativeRegExp.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$8 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$8")
public static Object getGroup8(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(8);
}
 
Example #12
Source File: NativeRegExp.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.lastParen property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "lastParen")
public static Object getLastParen(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getLastParen();
}
 
Example #13
Source File: NativeRegExp.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$9 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$9")
public static Object getGroup9(Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(9);
}
 
Example #14
Source File: NativeRegExp.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$8 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$8")
public static Object getGroup8(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(8);
}
 
Example #15
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$7 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$7")
public static Object getGroup7(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(7);
}
 
Example #16
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$6 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$6")
public static Object getGroup6(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(6);
}
 
Example #17
Source File: Global.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
void setLastRegExpResult(final RegExpResult regExpResult) {
    this.lastRegExpResult = regExpResult;
}
 
Example #18
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$4 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$4")
public static Object getGroup4(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(4);
}
 
Example #19
Source File: NativeRegExp.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Breaks up a string into an array of substrings based on a regular
 * expression or fixed string.
 *
 * @param string String to match.
 * @param limit  Split limit.
 * @return Array of substrings.
 */
NativeArray split(final String string, final long limit) {
    if (limit == 0L) {
        return new NativeArray();
    }

    final List<Object> matches = new ArrayList<>();

    RegExpResult match;
    final int inputLength = string.length();
    int splitLastLength = -1;
    int splitLastIndex = 0;
    int splitLastLastIndex = 0;

    while ((match = execSplit(string, splitLastIndex)) != null) {
        splitLastIndex = match.getIndex() + match.length();

        if (splitLastIndex > splitLastLastIndex) {
            matches.add(string.substring(splitLastLastIndex, match.getIndex()));
            final Object[] groups = match.getGroups();
            if (groups.length > 1 && match.getIndex() < inputLength) {
                for (int index = 1; index < groups.length && matches.size() < limit; index++) {
                    matches.add(groups[index]);
                }
            }

            splitLastLength = match.length();

            if (matches.size() >= limit) {
                break;
            }
        }

        // bump the index to avoid infinite loop
        if (splitLastIndex == splitLastLastIndex) {
            splitLastIndex++;
        } else {
            splitLastLastIndex = splitLastIndex;
        }
    }

    if (matches.size() < limit) {
        // check special case if we need to append an empty string at the
        // end of the match
        // if the lastIndex was the entire string
        if (splitLastLastIndex == string.length()) {
            if (splitLastLength > 0 || execSplit("", 0) == null) {
                matches.add("");
            }
        } else {
            matches.add(string.substring(splitLastLastIndex, inputLength));
        }
    }

    return new NativeArray(matches.toArray());
}
 
Example #20
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$2 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$2")
public static Object getGroup2(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(2);
}
 
Example #21
Source File: NativeRegExp.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$9 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$9")
public static Object getGroup9(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(9);
}
 
Example #22
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$1 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$1")
public static Object getGroup1(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(1);
}
 
Example #23
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.rightContext property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "rightContext")
public static Object getRightContext(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getInput().substring(match.getIndex() + match.length());
}
 
Example #24
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.leftContext property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "leftContext")
public static Object getLeftContext(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getInput().substring(0, match.getIndex());
}
 
Example #25
Source File: NativeRegExp.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.input property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "input")
public static Object getLastInput(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getInput();
}
 
Example #26
Source File: NativeRegExp.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Breaks up a string into an array of substrings based on a regular
 * expression or fixed string.
 *
 * @param string String to match.
 * @param limit  Split limit.
 * @return Array of substrings.
 */
Object split(final String string, final long limit) {
    if (limit == 0L) {
        return new NativeArray();
    }

    final List<Object> matches = new ArrayList<>();

    RegExpResult match;
    final int inputLength = string.length();
    int splitLastLength = -1;
    int splitLastIndex = 0;
    int splitLastLastIndex = 0;

    while ((match = execSplit(string, splitLastIndex)) != null) {
        splitLastIndex = match.getIndex() + match.length();

        if (splitLastIndex > splitLastLastIndex) {
            matches.add(string.substring(splitLastLastIndex, match.getIndex()));
            final Object[] groups = match.getGroups();
            if (groups.length > 1 && match.getIndex() < inputLength) {
                for (int index = 1; index < groups.length && matches.size() < limit; index++) {
                    matches.add(groups[index]);
                }
            }

            splitLastLength = match.length();

            if (matches.size() >= limit) {
                break;
            }
        }

        // bump the index to avoid infinite loop
        if (splitLastIndex == splitLastLastIndex) {
            splitLastIndex++;
        } else {
            splitLastLastIndex = splitLastIndex;
        }
    }

    if (matches.size() < limit) {
        // check special case if we need to append an empty string at the
        // end of the match
        // if the lastIndex was the entire string
        if (splitLastLastIndex == string.length()) {
            if (splitLastLength > 0 || execSplit("", 0) == null) {
                matches.add("");
            }
        } else {
            matches.add(string.substring(splitLastLastIndex, inputLength));
        }
    }

    return new NativeArray(matches.toArray());
}
 
Example #27
Source File: NativeRegExp.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.lastMatch property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "lastMatch")
public static Object getLastMatch(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(0);
}
 
Example #28
Source File: NativeRegExp.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.lastMatch property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "lastMatch")
public static Object getLastMatch(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(0);
}
 
Example #29
Source File: NativeRegExp.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$5 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$5")
public static Object getGroup5(Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(5);
}
 
Example #30
Source File: NativeRegExp.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Getter for non-standard RegExp.$2 property.
 * @param self self object
 * @return last regexp input
 */
@Getter(where = Where.CONSTRUCTOR, attributes = Attribute.CONSTANT, name = "$2")
public static Object getGroup2(final Object self) {
    final RegExpResult match = Global.instance().getLastRegExpResult();
    return match == null ? "" : match.getGroup(2);
}