aboutsummaryrefslogtreecommitdiff
path: root/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java')
-rw-r--r--src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java72
1 files changed, 46 insertions, 26 deletions
diff --git a/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java b/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java
index 91117d1d..bd335bb7 100644
--- a/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java
+++ b/src/jdk/nashorn/internal/runtime/regexp/joni/Regex.java
@@ -24,6 +24,7 @@ import jdk.nashorn.internal.runtime.regexp.joni.constants.RegexState;
import jdk.nashorn.internal.runtime.regexp.joni.exception.ErrorMessages;
import jdk.nashorn.internal.runtime.regexp.joni.exception.ValueException;
+@SuppressWarnings("javadoc")
public final class Regex implements RegexState {
int[] code; /* compiled pattern */
@@ -72,42 +73,43 @@ public final class Regex implements RegexState {
char[][] templates;
int templateNum;
- public Regex(CharSequence cs) {
+ public Regex(final CharSequence cs) {
this(cs.toString());
}
- public Regex(String str) {
+ public Regex(final String str) {
this(str.toCharArray(), 0, str.length(), 0);
}
- public Regex(char[] chars) {
+ public Regex(final char[] chars) {
this(chars, 0, chars.length, 0);
}
- public Regex(char[] chars, int p, int end) {
+ public Regex(final char[] chars, final int p, final int end) {
this(chars, p, end, 0);
}
- public Regex(char[] chars, int p, int end, int option) {
+ public Regex(final char[] chars, final int p, final int end, final int option) {
this(chars, p, end, option, Syntax.RUBY, WarnCallback.DEFAULT);
}
// onig_new
- public Regex(char[] chars, int p, int end, int option, Syntax syntax) {
+ public Regex(final char[] chars, final int p, final int end, final int option, final Syntax syntax) {
this(chars, p, end, option, Config.ENC_CASE_FOLD_DEFAULT, syntax, WarnCallback.DEFAULT);
}
- public Regex(char[]chars, int p, int end, int option, WarnCallback warnings) {
+ public Regex(final char[]chars, final int p, final int end, final int option, final WarnCallback warnings) {
this(chars, p, end, option, Syntax.RUBY, warnings);
}
// onig_new
- public Regex(char[] chars, int p, int end, int option, Syntax syntax, WarnCallback warnings) {
+ public Regex(final char[] chars, final int p, final int end, final int option, final Syntax syntax, final WarnCallback warnings) {
this(chars, p, end, option, Config.ENC_CASE_FOLD_DEFAULT, syntax, warnings);
}
// onig_alloc_init
- public Regex(char[] chars, int p, int end, int option, int caseFoldFlag, Syntax syntax, WarnCallback warnings) {
+ public Regex(final char[] chars, final int p, final int end, final int optionp, final int caseFoldFlag, final Syntax syntax, final WarnCallback warnings) {
+ int option = optionp;
if ((option & (Option.DONT_CAPTURE_GROUP | Option.CAPTURE_GROUP)) ==
(Option.DONT_CAPTURE_GROUP | Option.CAPTURE_GROUP)) {
@@ -140,11 +142,11 @@ public final class Regex implements RegexState {
return factory;
}
- public Matcher matcher(char[] chars) {
+ public Matcher matcher(final char[] chars) {
return matcher(chars, 0, chars.length);
}
- public Matcher matcher(char[] chars, int p, int end) {
+ public Matcher matcher(final char[] chars, final int p, final int end) {
MatcherFactory matcherFactory = factory;
if (matcherFactory == null) {
matcherFactory = compile();
@@ -162,26 +164,40 @@ public final class Regex implements RegexState {
/* set skip map for Boyer-Moor search */
void setupBMSkipMap() {
- char[] chars = exact;
- int p = exactP;
- int end = exactEnd;
- int len = end - p;
+ final char[] chars = exact;
+ final int p = exactP;
+ final int end = exactEnd;
+ final int len = end - p;
if (len < Config.CHAR_TABLE_SIZE) {
// map/skip
- if (map == null) map = new byte[Config.CHAR_TABLE_SIZE];
+ if (map == null) {
+ map = new byte[Config.CHAR_TABLE_SIZE];
+ }
- for (int i=0; i<Config.CHAR_TABLE_SIZE; i++) map[i] = (byte)len;
- for (int i=0; i<len-1; i++) map[chars[p + i] & 0xff] = (byte)(len - 1 -i); // oxff ??
+ for (int i=0; i<Config.CHAR_TABLE_SIZE; i++) {
+ map[i] = (byte)len;
+ }
+ for (int i=0; i<len-1; i++)
+ {
+ map[chars[p + i] & 0xff] = (byte)(len - 1 -i); // oxff ??
+ }
} else {
- if (intMap == null) intMap = new int[Config.CHAR_TABLE_SIZE];
+ if (intMap == null) {
+ intMap = new int[Config.CHAR_TABLE_SIZE];
+ }
- for (int i=0; i<len-1; i++) intMap[chars[p + i] & 0xff] = len - 1 - i; // oxff ??
+ for (int i=0; i<len-1; i++)
+ {
+ intMap[chars[p + i] & 0xff] = len - 1 - i; // oxff ??
+ }
}
}
- void setExactInfo(OptExactInfo e) {
- if (e.length == 0) return;
+ void setExactInfo(final OptExactInfo e) {
+ if (e.length == 0) {
+ return;
+ }
// shall we copy that ?
exact = e.chars;
@@ -207,7 +223,7 @@ public final class Regex implements RegexState {
}
}
- void setOptimizeMapInfo(OptMapInfo m) {
+ void setOptimizeMapInfo(final OptMapInfo m) {
map = m.map;
searchAlgorithm = SearchAlgorithm.MAP;
@@ -219,7 +235,7 @@ public final class Regex implements RegexState {
}
}
- void setSubAnchor(OptAnchorInfo anc) {
+ void setSubAnchor(final OptAnchorInfo anc) {
subAnchor |= anc.leftAnchor & AnchorType.BEGIN_LINE;
subAnchor |= anc.rightAnchor & AnchorType.END_LINE;
}
@@ -236,7 +252,7 @@ public final class Regex implements RegexState {
}
public String optimizeInfoToString() {
- StringBuilder s = new StringBuilder();
+ final StringBuilder s = new StringBuilder();
s.append("optimize: ").append(searchAlgorithm.getName()).append("\n");
s.append(" anchor: ").append(OptAnchorInfo.anchorToString(anchor));
@@ -257,7 +273,11 @@ public final class Regex implements RegexState {
s.append("exact: [").append(exact, exactP, exactEnd - exactP).append("]: length: ").append(exactEnd - exactP).append("\n");
} else if (searchAlgorithm == SearchAlgorithm.MAP) {
int n=0;
- for (int i=0; i<Config.CHAR_TABLE_SIZE; i++) if (map[i] != 0) n++;
+ for (int i=0; i<Config.CHAR_TABLE_SIZE; i++) {
+ if (map[i] != 0) {
+ n++;
+ }
+ }
s.append("map: n = ").append(n).append("\n");
if (n > 0) {