diff --git a/java/com/google/re2j/CharClass.java b/java/io/trino/re2j/CharClass.java similarity index 99% rename from java/com/google/re2j/CharClass.java rename to java/io/trino/re2j/CharClass.java index ea2b8f9d..8d560377 100644 --- a/java/com/google/re2j/CharClass.java +++ b/java/io/trino/re2j/CharClass.java @@ -5,7 +5,7 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/parse.go -package com.google.re2j; +package io.trino.re2j; /** * A "builder"-style helper class for manipulating character classes diff --git a/java/com/google/re2j/CharGroup.java b/java/io/trino/re2j/CharGroup.java similarity index 99% rename from java/com/google/re2j/CharGroup.java rename to java/io/trino/re2j/CharGroup.java index 0a60659d..9132fbe7 100644 --- a/java/com/google/re2j/CharGroup.java +++ b/java/io/trino/re2j/CharGroup.java @@ -1,7 +1,7 @@ // GENERATED BY make_perl_groups.pl; DO NOT EDIT. // make_perl_groups.pl >perl_groups.go -package com.google.re2j; +package io.trino.re2j; import java.util.HashMap; diff --git a/java/com/google/re2j/Compiler.java b/java/io/trino/re2j/Compiler.java similarity index 96% rename from java/com/google/re2j/Compiler.java rename to java/io/trino/re2j/Compiler.java index fe1a9a07..5a701eb3 100644 --- a/java/com/google/re2j/Compiler.java +++ b/java/io/trino/re2j/Compiler.java @@ -5,19 +5,19 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/compile.go -package com.google.re2j; +package io.trino.re2j; import java.util.LinkedList; import java.util.List; -import static com.google.re2j.Inst.Op.BYTE; -import static com.google.re2j.Inst.Op.BYTE1; -import static com.google.re2j.RE2.FOLD_CASE; -import static com.google.re2j.Unicode.RUNE_SELF; -import static com.google.re2j.Unicode.UTF_MAX; -import static com.google.re2j.Unicode.codePointToUtf8; -import static com.google.re2j.Unicode.maxRune; -import static com.google.re2j.Unicode.simpleFold; +import static io.trino.re2j.Inst.Op.BYTE; +import static io.trino.re2j.Inst.Op.BYTE1; +import static io.trino.re2j.RE2.FOLD_CASE; +import static io.trino.re2j.Unicode.RUNE_SELF; +import static io.trino.re2j.Unicode.UTF_MAX; +import static io.trino.re2j.Unicode.codePointToUtf8; +import static io.trino.re2j.Unicode.maxRune; +import static io.trino.re2j.Unicode.simpleFold; /** * Compiler from {@code Regexp} (RE2 abstract syntax) to {@code RE2} (compiled regular expression). diff --git a/java/com/google/re2j/DFA.java b/java/io/trino/re2j/DFA.java similarity index 94% rename from java/com/google/re2j/DFA.java rename to java/io/trino/re2j/DFA.java index 26b97658..b999a16e 100644 --- a/java/com/google/re2j/DFA.java +++ b/java/io/trino/re2j/DFA.java @@ -5,26 +5,20 @@ // Original RE2 source here: // https://github.com/google/re2/blob/master/re2/dfa.cc -package com.google.re2j; - -import com.google.re2j.RE2.MatchKind; +package io.trino.re2j; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -import static com.google.re2j.DFAState.DEAD_STATE; -import static com.google.re2j.Inst.Op.EMPTY_WIDTH; -import static com.google.re2j.MachineInput.EOF; -import static com.google.re2j.RE2.MatchKind.FIRST_MATCH; -import static com.google.re2j.RE2.MatchKind.LONGEST_MATCH; -import static com.google.re2j.Utils.EMPTY_BEGIN_LINE; -import static com.google.re2j.Utils.EMPTY_BEGIN_TEXT; -import static com.google.re2j.Utils.EMPTY_END_LINE; -import static com.google.re2j.Utils.EMPTY_END_TEXT; -import static com.google.re2j.Utils.EMPTY_NO_WORD_BOUNDARY; -import static com.google.re2j.Utils.EMPTY_WORD_BOUNDARY; -import static com.google.re2j.Utils.isRuneStart; -import static com.google.re2j.Utils.isWordByte; +import static io.trino.re2j.MachineInput.EOF; +import static io.trino.re2j.Utils.EMPTY_BEGIN_LINE; +import static io.trino.re2j.Utils.EMPTY_BEGIN_TEXT; +import static io.trino.re2j.Utils.EMPTY_END_LINE; +import static io.trino.re2j.Utils.EMPTY_END_TEXT; +import static io.trino.re2j.Utils.EMPTY_NO_WORD_BOUNDARY; +import static io.trino.re2j.Utils.EMPTY_WORD_BOUNDARY; +import static io.trino.re2j.Utils.isRuneStart; +import static io.trino.re2j.Utils.isWordByte; import static java.util.Arrays.sort; class DFA { @@ -51,7 +45,7 @@ private DFATooManyStatesException() { private static final int START_PARAMS_CACHE_SIZE = 1 << 13; private static final int START_PARAMS_CACHE_SHIFT = 12; - private static final StartParams DEAD_START_PARAMS = new StartParams(DEAD_STATE, new boolean[256]); + private static final StartParams DEAD_START_PARAMS = new StartParams(DFAState.DEAD_STATE, new boolean[256]); // Info for the search private final Prog prog; @@ -60,7 +54,7 @@ private DFATooManyStatesException() { private final Inst[] instructions; // Search for longest match like egrep or POSIX or for first match like Perl, PCRE - private final MatchKind matchKind; + private final RE2.MatchKind matchKind; // Should input bytes be read forward or backward private final boolean runForward; @@ -74,7 +68,7 @@ private DFATooManyStatesException() { private final ConcurrentHashMap statesCache; private final AtomicInteger availableStates; - public DFA(Prog prog, MatchKind matchKind, boolean reversed, + public DFA(Prog prog, RE2.MatchKind matchKind, boolean reversed, ConcurrentHashMap statesCache, AtomicInteger availableStates) { this.prog = prog; this.instructions = prog.getInst(); @@ -85,7 +79,7 @@ public DFA(Prog prog, MatchKind matchKind, boolean reversed, int progSize = prog.numInst(); int nMarks = 0; - if (matchKind == LONGEST_MATCH) { + if (matchKind == RE2.MatchKind.LONGEST_MATCH) { nMarks = progSize; } @@ -130,7 +124,7 @@ private DFAState workQueueToCachedState(WorkQueue q, int flag) { case MATCH: case ALT: instIndexes[nIndexes++] = instIndex; - if (inst.op() == EMPTY_WIDTH) { + if (inst.op() == Inst.Op.EMPTY_WIDTH) { neededFlags |= inst.arg; } break; @@ -153,13 +147,13 @@ private DFAState workQueueToCachedState(WorkQueue q, int flag) { // No match possibilities if (nIndexes == 0 && flag == 0) { - return DEAD_STATE; + return DFAState.DEAD_STATE; } // If we're in the longest match mode, the state is a sequence of // unordered state sets separated by Marks. Sort each set to // canonicalize, to reduce the number of distinct sets stored. - if (matchKind == LONGEST_MATCH) { + if (matchKind == RE2.MatchKind.LONGEST_MATCH) { int ip = 0; while (ip < nIndexes) { int markp = ip; @@ -322,7 +316,7 @@ private boolean runWorkQueueOnByte(byte b, int flag) { break; case MATCH: isMatch = true; - if (matchKind == FIRST_MATCH) { + if (matchKind == RE2.MatchKind.FIRST_MATCH) { return true; } break; diff --git a/java/com/google/re2j/DFAMachine.java b/java/io/trino/re2j/DFAMachine.java similarity index 79% rename from java/com/google/re2j/DFAMachine.java rename to java/io/trino/re2j/DFAMachine.java index 21dcb375..56834e83 100644 --- a/java/com/google/re2j/DFAMachine.java +++ b/java/io/trino/re2j/DFAMachine.java @@ -5,18 +5,12 @@ // Original RE2 source here: // https://github.com/google/re2/blob/master/re2/dfa.cc -package com.google.re2j; - -import com.google.re2j.RE2.Anchor; -import com.google.re2j.RE2.MatchKind; +package io.trino.re2j; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; -import static com.google.re2j.DFA.NO_MATCH; -import static com.google.re2j.RE2.Anchor.ANCHOR_START; -import static com.google.re2j.RE2.MatchKind.FIRST_MATCH; -import static com.google.re2j.RE2.MatchKind.LONGEST_MATCH; +import static io.trino.re2j.DFA.NO_MATCH; /** * A {@link Machine} implementation using a DFA. @@ -40,14 +34,14 @@ class DFAMachine implements Machine { stateCache[i] = new ConcurrentHashMap<>(); } - setDfaThreadLocal(LONGEST_MATCH, true); - setDfaThreadLocal(LONGEST_MATCH, false); - setDfaThreadLocal(FIRST_MATCH, true); - setDfaThreadLocal(FIRST_MATCH, false); + setDfaThreadLocal(RE2.MatchKind.LONGEST_MATCH, true); + setDfaThreadLocal(RE2.MatchKind.LONGEST_MATCH, false); + setDfaThreadLocal(RE2.MatchKind.FIRST_MATCH, true); + setDfaThreadLocal(RE2.MatchKind.FIRST_MATCH, false); } @Override - public boolean match(MachineInput in, int pos, Anchor anchor, int[] submatches) { + public boolean match(MachineInput in, int pos, RE2.Anchor anchor, int[] submatches) { // Don't ask for the location if we won't use it. SearchDFA can do extra optimizations in that case. boolean wantMatchPosition = true; if (submatches.length == 0) { @@ -71,7 +65,7 @@ public boolean match(MachineInput in, int pos, Anchor anchor, int[] submatches) // SearchDFA gives match end position but we don't know where the match started. Run the // regexp backwards from end position to find the longest possible match -- that's where it started. - matchStart = searchDFA(in, pos, matchEnd, ANCHOR_START, true, LONGEST_MATCH, true); + matchStart = searchDFA(in, pos, matchEnd, RE2.Anchor.ANCHOR_START, true, RE2.MatchKind.LONGEST_MATCH, true); if (matchStart == NO_MATCH) { throw new IllegalStateException("reverse DFA did not found a match"); } @@ -101,7 +95,7 @@ public boolean match(MachineInput in, int pos, Anchor anchor, int[] submatches) return true; } - private int searchDFA(MachineInput in, int startPos, int endPos, Anchor anchor, boolean wantMatchPosition, MatchKind matchKind, boolean reversed) { + private int searchDFA(MachineInput in, int startPos, int endPos, RE2.Anchor anchor, boolean wantMatchPosition, RE2.MatchKind matchKind, boolean reversed) { boolean hasCarat = reversed ? anchor.isAnchorEnd() : anchor.isAnchorStart(); if (hasCarat && startPos != 0) { return NO_MATCH; @@ -112,7 +106,7 @@ private int searchDFA(MachineInput in, int startPos, int endPos, Anchor anchor, boolean endMatch = false; if (anchor.isAnchorEnd()) { endMatch = true; - matchKind = LONGEST_MATCH; + matchKind = RE2.MatchKind.LONGEST_MATCH; } // If the caller doesn't care where the match is (just whether one exists), @@ -121,7 +115,7 @@ private int searchDFA(MachineInput in, int startPos, int endPos, Anchor anchor, boolean wantEarliestMatch = false; if (!wantMatchPosition && !endMatch) { wantEarliestMatch = true; - matchKind = LONGEST_MATCH; + matchKind = RE2.MatchKind.LONGEST_MATCH; } DFA dfa = getDfa(matchKind, reversed); @@ -140,17 +134,17 @@ private int searchDFA(MachineInput in, int startPos, int endPos, Anchor anchor, return match; } - private DFA getDfa(MatchKind matchKind, boolean reversed) { + private DFA getDfa(RE2.MatchKind matchKind, boolean reversed) { return dfaCache[dfaKey(matchKind, reversed)].get(); } - private int dfaKey(MatchKind matchKind, boolean reversed) { - int longestInt = matchKind == LONGEST_MATCH ? 1 : 0; + private int dfaKey(RE2.MatchKind matchKind, boolean reversed) { + int longestInt = matchKind == RE2.MatchKind.LONGEST_MATCH ? 1 : 0; int reversedInt = reversed ? 1 : 0; return longestInt | (reversedInt << 1); } - private void setDfaThreadLocal(MatchKind matchKind, boolean reversed) { + private void setDfaThreadLocal(RE2.MatchKind matchKind, boolean reversed) { int dfaKey = dfaKey(matchKind, reversed); Prog prog = reversed ? re2.reverseProg : re2.prog; dfaCache[dfaKey] = new ThreadLocal() { diff --git a/java/com/google/re2j/DFAState.java b/java/io/trino/re2j/DFAState.java similarity index 90% rename from java/com/google/re2j/DFAState.java rename to java/io/trino/re2j/DFAState.java index 088fc521..ebc42d80 100644 --- a/java/com/google/re2j/DFAState.java +++ b/java/io/trino/re2j/DFAState.java @@ -5,11 +5,11 @@ // Original RE2 source here: // https://github.com/google/re2/blob/master/re2/dfa.cc -package com.google.re2j; +package io.trino.re2j; -import static com.google.re2j.DFA.FLAG_MATCH; -import static com.google.re2j.DFAState.StateType.DEAD; -import static com.google.re2j.DFAState.StateType.REGULAR; +import static io.trino.re2j.DFA.FLAG_MATCH; +import static io.trino.re2j.DFAState.StateType.DEAD; +import static io.trino.re2j.DFAState.StateType.REGULAR; import static java.lang.System.arraycopy; final class DFAState { diff --git a/java/com/google/re2j/DFAStateKey.java b/java/io/trino/re2j/DFAStateKey.java similarity index 92% rename from java/com/google/re2j/DFAStateKey.java rename to java/io/trino/re2j/DFAStateKey.java index 97d7fbfb..0e6a7ef9 100644 --- a/java/com/google/re2j/DFAStateKey.java +++ b/java/io/trino/re2j/DFAStateKey.java @@ -5,11 +5,11 @@ // Original RE2 source here: // https://github.com/google/re2/blob/master/re2/dfa.cc -package com.google.re2j; +package io.trino.re2j; import java.util.Arrays; -import static com.google.re2j.Utils.arrayFirstElementsEqual; +import static io.trino.re2j.Utils.arrayFirstElementsEqual; final class DFAStateKey { private final int[] instIndexes; diff --git a/java/com/google/re2j/Inst.java b/java/io/trino/re2j/Inst.java similarity index 97% rename from java/com/google/re2j/Inst.java rename to java/io/trino/re2j/Inst.java index e50d3f24..6e444a77 100644 --- a/java/com/google/re2j/Inst.java +++ b/java/io/trino/re2j/Inst.java @@ -5,9 +5,9 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/prog.go -package com.google.re2j; +package io.trino.re2j; -import static com.google.re2j.Inst.Op.BYTE; +import static io.trino.re2j.Inst.Op.BYTE; /** * A single instruction in the regular expression virtual machine. diff --git a/java/com/google/re2j/Machine.java b/java/io/trino/re2j/Machine.java similarity index 91% rename from java/com/google/re2j/Machine.java rename to java/io/trino/re2j/Machine.java index 14fb8208..1f33efa0 100644 --- a/java/com/google/re2j/Machine.java +++ b/java/io/trino/re2j/Machine.java @@ -5,9 +5,9 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/exec.go -package com.google.re2j; +package io.trino.re2j; -import com.google.re2j.RE2.Anchor; +import io.trino.re2j.RE2.Anchor; /** * A Machine matches an input string of Unicode characters against an RE2 instance. diff --git a/java/com/google/re2j/MachineInput.java b/java/io/trino/re2j/MachineInput.java similarity index 98% rename from java/com/google/re2j/MachineInput.java rename to java/io/trino/re2j/MachineInput.java index 1e3f33ec..eb4af435 100644 --- a/java/com/google/re2j/MachineInput.java +++ b/java/io/trino/re2j/MachineInput.java @@ -5,7 +5,7 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/regexp.go -package com.google.re2j; +package io.trino.re2j; import io.airlift.slice.Slice; diff --git a/java/com/google/re2j/Matcher.java b/java/io/trino/re2j/Matcher.java similarity index 96% rename from java/com/google/re2j/Matcher.java rename to java/io/trino/re2j/Matcher.java index 2a657e36..9bddd5b5 100644 --- a/java/com/google/re2j/Matcher.java +++ b/java/io/trino/re2j/Matcher.java @@ -1,17 +1,11 @@ // Copyright 2010 Google Inc. All Rights Reserved. -package com.google.re2j; - -import com.google.re2j.RE2.Anchor; +package io.trino.re2j; import io.airlift.slice.DynamicSliceOutput; import io.airlift.slice.Slice; import io.airlift.slice.SliceOutput; -import static com.google.re2j.RE2.Anchor.ANCHOR_BOTH; -import static com.google.re2j.RE2.Anchor.ANCHOR_START; -import static com.google.re2j.RE2.Anchor.UNANCHORED; - /** * A stateful iterator that interprets a regex {@code Pattern} on a * specific input. Its interface mimics the JDK 1.4.2 @@ -64,7 +58,7 @@ public final class Matcher { private boolean hasGroups; // The anchor flag to use when repeating the match to find subgroups. - private Anchor anchorFlag; + private RE2.Anchor anchorFlag; private Matcher(Pattern pattern) { if (pattern == null) { @@ -236,7 +230,7 @@ private void loadGroup(int group) { * @return true if the entire input matches the pattern */ public boolean matches() { - return genMatch(0, ANCHOR_BOTH); + return genMatch(0, RE2.Anchor.ANCHOR_BOTH); } /** @@ -246,7 +240,7 @@ public boolean matches() { * @return true if the beginning of the input matches the pattern */ public boolean lookingAt() { - return genMatch(0, ANCHOR_START); + return genMatch(0, RE2.Anchor.ANCHOR_START); } /** @@ -265,7 +259,7 @@ public boolean find() { start++; } } - return genMatch(start, UNANCHORED); + return genMatch(start, RE2.Anchor.UNANCHORED); } /** @@ -283,11 +277,11 @@ public boolean find(int start) { "start index out of bounds: " + start); } reset(); - return genMatch(start, UNANCHORED); + return genMatch(start, RE2.Anchor.UNANCHORED); } /** Helper: does match starting at start, with RE2 anchor flag. */ - private boolean genMatch(int startByte, Anchor anchor) { + private boolean genMatch(int startByte, RE2.Anchor anchor) { // TODO(rsc): Is matches/lookingAt supposed to reset the append or input positions? // From the JDK docs, looks like no. boolean ok = pattern.re2().match(input, startByte, diff --git a/java/com/google/re2j/NFAMachine.java b/java/io/trino/re2j/NFAMachine.java similarity index 97% rename from java/com/google/re2j/NFAMachine.java rename to java/io/trino/re2j/NFAMachine.java index 6069034a..77c5d312 100644 --- a/java/com/google/re2j/NFAMachine.java +++ b/java/io/trino/re2j/NFAMachine.java @@ -5,16 +5,16 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/exec.go -package com.google.re2j; +package io.trino.re2j; -import com.google.re2j.RE2.Anchor; +import io.trino.re2j.RE2.Anchor; import java.util.Arrays; -import static com.google.re2j.MachineInput.EOF; -import static com.google.re2j.RE2.MatchKind.LONGEST_MATCH; -import static com.google.re2j.Utils.emptyOpContext; -import static com.google.re2j.Utils.isRuneStart; +import static io.trino.re2j.MachineInput.EOF; +import static io.trino.re2j.RE2.MatchKind.LONGEST_MATCH; +import static io.trino.re2j.Utils.emptyOpContext; +import static io.trino.re2j.Utils.isRuneStart; import static java.lang.System.arraycopy; /** diff --git a/java/com/google/re2j/Options.java b/java/io/trino/re2j/Options.java similarity index 98% rename from java/com/google/re2j/Options.java rename to java/io/trino/re2j/Options.java index f5e41c3d..9ea461ea 100644 --- a/java/com/google/re2j/Options.java +++ b/java/io/trino/re2j/Options.java @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package com.google.re2j; +package io.trino.re2j; import java.io.Serializable; -import static com.google.re2j.Options.Algorithm.DFA; +import static io.trino.re2j.Options.Algorithm.DFA; import static java.util.Objects.requireNonNull; public final class Options implements Serializable { diff --git a/java/com/google/re2j/Parser.java b/java/io/trino/re2j/Parser.java similarity index 99% rename from java/com/google/re2j/Parser.java rename to java/io/trino/re2j/Parser.java index 2716c5d3..e870177d 100644 --- a/java/com/google/re2j/Parser.java +++ b/java/io/trino/re2j/Parser.java @@ -9,7 +9,7 @@ // - Eliminate allocations (new int[], new Regexp[], new ArrayList) by // recycling old arrays on a freelist. -package com.google.re2j; +package io.trino.re2j; import java.util.ArrayList; diff --git a/java/com/google/re2j/Pattern.java b/java/io/trino/re2j/Pattern.java similarity index 93% rename from java/com/google/re2j/Pattern.java rename to java/io/trino/re2j/Pattern.java index 408717b5..3ca073e9 100644 --- a/java/com/google/re2j/Pattern.java +++ b/java/io/trino/re2j/Pattern.java @@ -1,16 +1,11 @@ // Copyright 2010 Google Inc. All Rights Reserved. -package com.google.re2j; +package io.trino.re2j; import java.io.Serializable; import io.airlift.slice.Slice; -import static com.google.re2j.Options.DEFAULT_OPTIONS; -import static com.google.re2j.RE2.Anchor.ANCHOR_BOTH; -import static com.google.re2j.RE2.Anchor.UNANCHORED; -import static com.google.re2j.RE2.MatchKind.FIRST_MATCH; - /** * A compiled representation of an RE2 regular expression, mimicking the * {@code java.util.regex.Pattern} API. @@ -101,7 +96,7 @@ RE2 re2() { * @throws PatternSyntaxException if the pattern is malformed */ public static Pattern compile(String regex) { - return compile(regex, DEFAULT_OPTIONS); + return compile(regex, Options.DEFAULT_OPTIONS); } public static Pattern compile(String regex, Options options) { @@ -119,7 +114,7 @@ public static Pattern compile(String regex, Options options) { * @throws IllegalArgumentException if an unknown flag is given */ public static Pattern compile(String regex, int flags) { - return compile(regex, flags, DEFAULT_OPTIONS); + return compile(regex, flags, Options.DEFAULT_OPTIONS); } public static Pattern compile(String regex, int flags, Options options) { @@ -149,7 +144,7 @@ private static Pattern compile(String flregex, String regex, int flags, Options if ((flags & DISABLE_UNICODE_GROUPS) != 0) { re2Flags &= ~RE2.UNICODE_GROUPS; } - return new Pattern(regex, flags, RE2.compileImpl(flregex, re2Flags, FIRST_MATCH, options), options); + return new Pattern(regex, flags, RE2.compileImpl(flregex, re2Flags, RE2.MatchKind.FIRST_MATCH, options), options); } /** @@ -161,7 +156,7 @@ private static Pattern compile(String flregex, String regex, int flags, Options * @throws PatternSyntaxException if the regular expression is malformed */ public static boolean matches(String regex, Slice input) { - return matches(regex, input, DEFAULT_OPTIONS); + return matches(regex, input, Options.DEFAULT_OPTIONS); } public static boolean matches(String regex, Slice input, Options options) { @@ -169,7 +164,7 @@ public static boolean matches(String regex, Slice input, Options options) { } public boolean matches(Slice input) { - return re2.match(input, 0, ANCHOR_BOTH, null, 0); + return re2.match(input, 0, RE2.Anchor.ANCHOR_BOTH, null, 0); } /** @@ -181,7 +176,7 @@ public boolean matches(Slice input) { * @throws PatternSyntaxException if the regular expression is malformed */ public static boolean find(String regex, Slice input) { - return find(regex, input, DEFAULT_OPTIONS); + return find(regex, input, Options.DEFAULT_OPTIONS); } public static boolean find(String regex, Slice input, Options options) { @@ -189,7 +184,7 @@ public static boolean find(String regex, Slice input, Options options) { } public boolean find(Slice input) { - return re2.match(input, 0, UNANCHORED, null, 0); + return re2.match(input, 0, RE2.Anchor.UNANCHORED, null, 0); } /** diff --git a/java/com/google/re2j/PatternSyntaxException.java b/java/io/trino/re2j/PatternSyntaxException.java similarity index 98% rename from java/com/google/re2j/PatternSyntaxException.java rename to java/io/trino/re2j/PatternSyntaxException.java index dbd0d562..d9372962 100644 --- a/java/com/google/re2j/PatternSyntaxException.java +++ b/java/io/trino/re2j/PatternSyntaxException.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package com.google.re2j; +package io.trino.re2j; /** * An exception thrown by the parser if the pattern was invalid. diff --git a/java/com/google/re2j/Prog.java b/java/io/trino/re2j/Prog.java similarity index 93% rename from java/com/google/re2j/Prog.java rename to java/io/trino/re2j/Prog.java index 79a27f3a..bc330098 100644 --- a/java/com/google/re2j/Prog.java +++ b/java/io/trino/re2j/Prog.java @@ -5,7 +5,7 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/prog.go -package com.google.re2j; +package io.trino.re2j; import java.util.ArrayList; import java.util.List; @@ -13,9 +13,6 @@ import io.airlift.slice.SliceOutput; import io.airlift.slice.Slices; -import static com.google.re2j.Inst.Op.BYTE; -import static com.google.re2j.Inst.Op.MATCH; - /** * A Prog is a compiled regular expression program. */ @@ -69,12 +66,12 @@ boolean prefix(SliceOutput prefix) { Inst i = skipNop(start); // Avoid allocation of buffer if prefix is empty. - if (i.op() != BYTE || i.byteRanges.length != 1) { - return i.op == MATCH; // (append "" to prefix) + if (i.op() != Inst.Op.BYTE || i.byteRanges.length != 1) { + return i.op == Inst.Op.MATCH; // (append "" to prefix) } int length = 0; - while (i.op() == BYTE && i.byteRanges.length == 1) { + while (i.op() == Inst.Op.BYTE && i.byteRanges.length == 1) { i = skipNop(i.out); length++; } @@ -82,7 +79,7 @@ boolean prefix(SliceOutput prefix) { byte[] bytes = new byte[length]; length = 0; i = skipNop(start); - while (i.op() == BYTE && i.byteRanges.length == 1) { + while (i.op() == Inst.Op.BYTE && i.byteRanges.length == 1) { bytes[length] = i.byteRanges[0]; i = skipNop(i.out); length++; @@ -91,7 +88,7 @@ boolean prefix(SliceOutput prefix) { // Have prefix; gather characters. prefix.appendBytes(Slices.wrappedBuffer(bytes)); - return i.op == MATCH; + return i.op == Inst.Op.MATCH; } // startCond() returns the leading empty-width conditions that must be true diff --git a/java/com/google/re2j/RE2.java b/java/io/trino/re2j/RE2.java similarity index 97% rename from java/com/google/re2j/RE2.java rename to java/io/trino/re2j/RE2.java index a588034a..a198f47e 100644 --- a/java/com/google/re2j/RE2.java +++ b/java/io/trino/re2j/RE2.java @@ -16,9 +16,9 @@ // the primary input datatype, and the method names have been changed to // reflect this. -package com.google.re2j; +package io.trino.re2j; -import com.google.re2j.DFA.DFATooManyStatesException; +import io.trino.re2j.DFA.DFATooManyStatesException; import java.util.ArrayList; import java.util.Arrays; @@ -31,12 +31,10 @@ import io.airlift.slice.SliceOutput; import io.airlift.slice.Slices; -import static com.google.re2j.MachineInput.EOF; -import static com.google.re2j.Options.Algorithm.DFA; -import static com.google.re2j.Options.Algorithm.DFA_FALLBACK_TO_NFA; -import static com.google.re2j.RE2.Anchor.UNANCHORED; -import static com.google.re2j.RE2.MatchKind.FIRST_MATCH; -import static com.google.re2j.RE2.MatchKind.LONGEST_MATCH; +import static io.trino.re2j.MachineInput.EOF; +import static io.trino.re2j.RE2.Anchor.UNANCHORED; +import static io.trino.re2j.RE2.MatchKind.FIRST_MATCH; +import static io.trino.re2j.RE2.MatchKind.LONGEST_MATCH; /** * An RE2 class instance is a compiled representation of an RE2 regular @@ -185,7 +183,7 @@ private RE2(String expr, Prog prog, Prog reverseProg, int numSubexp, this.matchKind = matchKind; this.prefixComplete = prefixComplete; this.prefixUTF8 = prefixUTF8; - if (options.getAlgorithm() == DFA || options.getAlgorithm() == DFA_FALLBACK_TO_NFA) { + if (options.getAlgorithm() == Options.Algorithm.DFA || options.getAlgorithm() == Options.Algorithm.DFA_FALLBACK_TO_NFA) { this.dfaMachine = new DFAMachine(this, options.getMaximumNumberOfDFAStates()); this.numberOfDFARetriesLeft = new AtomicInteger(options.getNumberOfDFARetries()); } @@ -285,7 +283,7 @@ private synchronized void handleTooManyDFAStatesException(DFATooManyStatesExcept // make sure we don't penalize new DFAMachine instance if (currentDFAMachine == dfaMachine) { if (numberOfDFARetriesLeft.decrementAndGet() < 0) { - if (options.getAlgorithm() == DFA_FALLBACK_TO_NFA) { + if (options.getAlgorithm() == Options.Algorithm.DFA_FALLBACK_TO_NFA) { dfaMachine = null; if (options.getEventsListener() != null) { options.getEventsListener().fallbackToNFA(); diff --git a/java/com/google/re2j/Regexp.java b/java/io/trino/re2j/Regexp.java similarity index 99% rename from java/com/google/re2j/Regexp.java rename to java/io/trino/re2j/Regexp.java index e0381cbb..f664ddae 100644 --- a/java/com/google/re2j/Regexp.java +++ b/java/io/trino/re2j/Regexp.java @@ -5,7 +5,7 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/regexp.go -package com.google.re2j; +package io.trino.re2j; import java.util.Arrays; import java.util.HashMap; diff --git a/java/com/google/re2j/Simplify.java b/java/io/trino/re2j/Simplify.java similarity index 99% rename from java/com/google/re2j/Simplify.java rename to java/io/trino/re2j/Simplify.java index 7f6e549a..8fae6a8f 100644 --- a/java/com/google/re2j/Simplify.java +++ b/java/io/trino/re2j/Simplify.java @@ -5,7 +5,7 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/simplify.go -package com.google.re2j; +package io.trino.re2j; import java.util.ArrayList; diff --git a/java/com/google/re2j/SliceUtils.java b/java/io/trino/re2j/SliceUtils.java similarity index 99% rename from java/com/google/re2j/SliceUtils.java rename to java/io/trino/re2j/SliceUtils.java index 36da9d81..1fbe09dc 100644 --- a/java/com/google/re2j/SliceUtils.java +++ b/java/io/trino/re2j/SliceUtils.java @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.re2j; +package io.trino.re2j; import io.airlift.slice.Slice; import io.airlift.slice.SliceOutput; diff --git a/java/com/google/re2j/SparseSet.java b/java/io/trino/re2j/SparseSet.java similarity index 97% rename from java/com/google/re2j/SparseSet.java rename to java/io/trino/re2j/SparseSet.java index 3c9d9ee7..0e40c7e8 100644 --- a/java/com/google/re2j/SparseSet.java +++ b/java/io/trino/re2j/SparseSet.java @@ -5,7 +5,7 @@ // Original RE2 source here: // https://github.com/google/re2/blob/master/util/sparse_set.h -package com.google.re2j; +package io.trino.re2j; class SparseSet { private final int[] dense; // may contain stale Entries in slots >= size diff --git a/java/com/google/re2j/Unicode.java b/java/io/trino/re2j/Unicode.java similarity index 99% rename from java/com/google/re2j/Unicode.java rename to java/io/trino/re2j/Unicode.java index c7f69f02..d4123589 100644 --- a/java/com/google/re2j/Unicode.java +++ b/java/io/trino/re2j/Unicode.java @@ -5,7 +5,7 @@ // Many of these were derived from the corresponding Go functions in // http://code.google.com/p/go/source/browse/src/pkg/unicode/letter.go -package com.google.re2j; +package io.trino.re2j; import static java.nio.charset.StandardCharsets.UTF_8; diff --git a/java/com/google/re2j/UnicodeTables.java b/java/io/trino/re2j/UnicodeTables.java similarity index 99% rename from java/com/google/re2j/UnicodeTables.java rename to java/io/trino/re2j/UnicodeTables.java index da4aa451..c64b889e 100644 --- a/java/com/google/re2j/UnicodeTables.java +++ b/java/io/trino/re2j/UnicodeTables.java @@ -2,7 +2,7 @@ // go/src/pkg/unicode/maketables.go. Yes it's awful, but frankly // it's quicker than porting 1300 more lines of Go. -package com.google.re2j; +package io.trino.re2j; import java.util.HashMap; import java.util.Map; diff --git a/java/com/google/re2j/Utils.java b/java/io/trino/re2j/Utils.java similarity index 98% rename from java/com/google/re2j/Utils.java rename to java/io/trino/re2j/Utils.java index 1f86518d..8dbeba3e 100644 --- a/java/com/google/re2j/Utils.java +++ b/java/io/trino/re2j/Utils.java @@ -2,12 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package com.google.re2j; +package io.trino.re2j; import io.airlift.slice.Slice; -import static com.google.re2j.MachineInput.EOF; - /** * Various constants and helper utilities. */ @@ -177,13 +175,13 @@ static boolean isRuneStart(byte b) { // TODO(adonovan): move to Machine. static int emptyOpContext(byte b1, byte b2) { int op = 0; - if (b1 == EOF) { + if (b1 == MachineInput.EOF) { op |= EMPTY_BEGIN_TEXT | EMPTY_BEGIN_LINE; } if (b1 == '\n') { op |= EMPTY_BEGIN_LINE; } - if (b2 == EOF) { + if (b2 == MachineInput.EOF) { op |= EMPTY_END_TEXT | EMPTY_END_LINE; } if (b2 == '\n') { diff --git a/java/com/google/re2j/make_perl_groups.pl b/java/io/trino/re2j/make_perl_groups.pl similarity index 100% rename from java/com/google/re2j/make_perl_groups.pl rename to java/io/trino/re2j/make_perl_groups.pl diff --git a/java/com/google/re2j/make_unicode_tables.awk b/java/io/trino/re2j/make_unicode_tables.awk similarity index 100% rename from java/com/google/re2j/make_unicode_tables.awk rename to java/io/trino/re2j/make_unicode_tables.awk diff --git a/java/com/google/re2j/package.html b/java/io/trino/re2j/package.html similarity index 100% rename from java/com/google/re2j/package.html rename to java/io/trino/re2j/package.html diff --git a/javatests/com/google/re2j/ApiTest.java b/javatests/io/trino/re2j/ApiTest.java similarity index 99% rename from javatests/com/google/re2j/ApiTest.java rename to javatests/io/trino/re2j/ApiTest.java index b4f68897..92d50600 100644 --- a/javatests/com/google/re2j/ApiTest.java +++ b/javatests/io/trino/re2j/ApiTest.java @@ -1,6 +1,6 @@ // Copyright 2012 Google Inc. All Rights Reserved. -package com.google.re2j; +package io.trino.re2j; import com.google.common.base.Function; diff --git a/javatests/com/google/re2j/CharClassTest.java b/javatests/io/trino/re2j/CharClassTest.java similarity index 97% rename from javatests/com/google/re2j/CharClassTest.java rename to javatests/io/trino/re2j/CharClassTest.java index ab3e95f2..37eb6080 100644 --- a/javatests/com/google/re2j/CharClassTest.java +++ b/javatests/io/trino/re2j/CharClassTest.java @@ -3,9 +3,7 @@ // Partly plundered from third_party/re2/testing/charclass_test.cc, // updated to account for proper Unicode case folding. -package com.google.re2j; - -import static com.google.re2j.Utils.stringToRunes; +package io.trino.re2j; import static org.junit.Assert.assertEquals; @@ -17,7 +15,7 @@ public class CharClassTest { private static CharClass cc(int ... x) { return new CharClass(x); } private static int[] i(int ... x) { return x; } - private static int[] s(String s) { return stringToRunes(s); } + private static int[] s(String s) { return Utils.stringToRunes(s); } private static void assertClass(CharClass cc, int ... expected) { int actual[] = cc.toArray(); diff --git a/javatests/com/google/re2j/ExecTest.java b/javatests/io/trino/re2j/ExecTest.java similarity index 98% rename from javatests/com/google/re2j/ExecTest.java rename to javatests/io/trino/re2j/ExecTest.java index 29210cd3..38c7eca9 100644 --- a/javatests/com/google/re2j/ExecTest.java +++ b/javatests/io/trino/re2j/ExecTest.java @@ -5,8 +5,9 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/exec_test.go -package com.google.re2j; +package io.trino.re2j; +import com.google.common.collect.Lists; import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; @@ -23,9 +24,7 @@ import io.airlift.slice.Slice; import static com.google.common.collect.Lists.newArrayList; -import static com.google.re2j.ApiTest.slicesToStrings; -import static com.google.re2j.RE2.MatchKind.FIRST_MATCH; -import static com.google.re2j.RE2.MatchKind.LONGEST_MATCH; +import static io.trino.re2j.ApiTest.slicesToStrings; import static io.airlift.slice.Slices.utf8Slice; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -226,7 +225,7 @@ public void testRE2(String file) throws IOException { boolean partial = (i & 1) != 0, longest = (i & 2) != 0; RE2 regexp = partial ? re : refull; - regexp.matchKind = longest ? LONGEST_MATCH : FIRST_MATCH; + regexp.matchKind = longest ? RE2.MatchKind.LONGEST_MATCH : RE2.MatchKind.FIRST_MATCH; int[] have = regexp.findSubmatchIndex(utf8Slice(text)); // UTF-8 indices int[] want = parseResult(file, lineno, res[i]); // UTF-8 indices if (!Arrays.equals(want, have)) { @@ -242,7 +241,7 @@ public void testRE2(String file) throws IOException { continue; } - regexp.matchKind = longest ? LONGEST_MATCH : FIRST_MATCH; + regexp.matchKind = longest ? RE2.MatchKind.LONGEST_MATCH : RE2.MatchKind.FIRST_MATCH; boolean b = regexp.match(utf8Slice(text)); if (b != (want != null)) { System.err.format( @@ -376,7 +375,7 @@ private void testFowler(String file) throws IOException { continue; } - List field = newArrayList(slicesToStrings(NOTAB.findAll(utf8Slice(line), -1))); + List field = Lists.newArrayList(ApiTest.slicesToStrings(NOTAB.findAll(utf8Slice(line), -1))); for (int i = 0; i < field.size(); ++i) { if (field.get(i).equals("NULL")) { @@ -568,7 +567,7 @@ private void testFowler(String file) throws IOException { RE2 re = null; try { - re = RE2.compileImpl(pattern, flags, LONGEST_MATCH, options); + re = RE2.compileImpl(pattern, flags, RE2.MatchKind.LONGEST_MATCH, options); } catch (PatternSyntaxException e) { if (shouldCompileMatch[0]) { System.err.format("%s:%d: %s did not compile\n", diff --git a/javatests/com/google/re2j/FallbackToNFATest.java b/javatests/io/trino/re2j/FallbackToNFATest.java similarity index 94% rename from javatests/com/google/re2j/FallbackToNFATest.java rename to javatests/io/trino/re2j/FallbackToNFATest.java index 68189ea7..0c4b8b07 100644 --- a/javatests/com/google/re2j/FallbackToNFATest.java +++ b/javatests/io/trino/re2j/FallbackToNFATest.java @@ -5,16 +5,14 @@ // Original RE2 source here: // https://github.com/google/re2/blob/master/re2/testing/dfa_test.cc -package com.google.re2j; +package io.trino.re2j; -import com.google.re2j.DFA.DFATooManyStatesException; +import io.trino.re2j.DFA.DFATooManyStatesException; import org.junit.Test; import io.airlift.slice.Slice; -import static com.google.re2j.Options.Algorithm.DFA; -import static com.google.re2j.Options.Algorithm.DFA_FALLBACK_TO_NFA; import static io.airlift.slice.Slices.utf8Slice; import static java.lang.String.format; import static org.junit.Assert.assertEquals; @@ -51,7 +49,7 @@ public class FallbackToNFATest { @Test public void testFallbackToNFA() { Options options = Options.builder() - .setAlgorithm(DFA_FALLBACK_TO_NFA) + .setAlgorithm(Options.Algorithm.DFA_FALLBACK_TO_NFA) .setMaximumNumberOfDFAStates(1 << (N - 1)) .setNumberOfDFARetries(2) .setEventsListener(new TestEventsListener()) @@ -81,7 +79,7 @@ public void testFallbackToNFA() { @Test(expected = DFATooManyStatesException.class) public void testFailsTooManyDFAStates() { Options options = Options.builder() - .setAlgorithm(DFA) + .setAlgorithm(Options.Algorithm.DFA) .setMaximumNumberOfDFAStates(1 << (N - 1)) .setNumberOfDFARetries(2) .build(); diff --git a/javatests/com/google/re2j/FindTest.java b/javatests/io/trino/re2j/FindTest.java similarity index 98% rename from javatests/com/google/re2j/FindTest.java rename to javatests/io/trino/re2j/FindTest.java index 6b9a396d..5d382284 100644 --- a/javatests/com/google/re2j/FindTest.java +++ b/javatests/io/trino/re2j/FindTest.java @@ -9,7 +9,7 @@ // potential for confusion arising from systematic renamings // (e.g. "String" -> "", "" -> "UTF8", "Test" -> "test", etc.) -package com.google.re2j; +package io.trino.re2j; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; @@ -21,7 +21,7 @@ import io.airlift.slice.Slice; -import static com.google.re2j.ApiTest.slicesToStrings; +import static io.trino.re2j.ApiTest.slicesToStrings; import static io.airlift.slice.Slices.utf8Slice; import static org.junit.Assert.fail; @@ -258,7 +258,7 @@ public void testFindIndex() { @org.junit.Test public void testFindAll() { List slices = RE2.compile(test.pat, options).findAll(utf8Slice(test.text), -1); - List result = slicesToStrings(slices); + List result = ApiTest.slicesToStrings(slices); if (test.matches.length == 0 && result == null) { // ok } else if (test.matches.length == 0 && result != null) { @@ -366,7 +366,7 @@ private void testSubmatch(String testName, Test test, int n, @org.junit.Test public void testFindSubmatch() { Slice[] slices = RE2.compile(test.pat, options).findSubmatch(utf8Slice(test.text)); - List result = slicesToStrings(slices); + List result = ApiTest.slicesToStrings(slices); if (test.matches.length == 0 && result == null) { // ok } else if (test.matches.length == 0 && result != null) { @@ -433,7 +433,7 @@ public void testFindAllSubmatch() { test)); } else { for (int k = 0; k < test.matches.length; ++k) { - testSubmatch("testFindAllStringSubmatch", test, k, slicesToStrings(result.get(k))); + testSubmatch("testFindAllStringSubmatch", test, k, ApiTest.slicesToStrings(result.get(k))); } } } diff --git a/javatests/com/google/re2j/GoTestUtils.java b/javatests/io/trino/re2j/GoTestUtils.java similarity index 97% rename from javatests/com/google/re2j/GoTestUtils.java rename to javatests/io/trino/re2j/GoTestUtils.java index 6365893f..7d245d54 100644 --- a/javatests/com/google/re2j/GoTestUtils.java +++ b/javatests/io/trino/re2j/GoTestUtils.java @@ -1,6 +1,6 @@ // Copyright 2012 Google Inc. All Rights Reserved. -package com.google.re2j; +package io.trino.re2j; import java.io.UnsupportedEncodingException; diff --git a/javatests/com/google/re2j/MatcherTest.java b/javatests/io/trino/re2j/MatcherTest.java similarity index 99% rename from javatests/com/google/re2j/MatcherTest.java rename to javatests/io/trino/re2j/MatcherTest.java index 9e5fe202..e5e20aeb 100644 --- a/javatests/com/google/re2j/MatcherTest.java +++ b/javatests/io/trino/re2j/MatcherTest.java @@ -1,6 +1,6 @@ // Copyright 2012 Google Inc. All Rights Reserved. -package com.google.re2j; +package io.trino.re2j; import org.junit.Test; import org.junit.experimental.runners.Enclosed; diff --git a/javatests/com/google/re2j/OptionsTest.java b/javatests/io/trino/re2j/OptionsTest.java similarity index 75% rename from javatests/com/google/re2j/OptionsTest.java rename to javatests/io/trino/re2j/OptionsTest.java index 02a248aa..3c029b11 100644 --- a/javatests/com/google/re2j/OptionsTest.java +++ b/javatests/io/trino/re2j/OptionsTest.java @@ -2,10 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package com.google.re2j; - -import static com.google.re2j.Options.Algorithm.DFA; -import static com.google.re2j.Options.Algorithm.NFA; +package io.trino.re2j; /** * Stores information about specified {@link Options} for constructing {@link Pattern} and {@link @@ -13,8 +10,8 @@ */ public abstract class OptionsTest { - public static final Options RUN_WITH_DFA = Options.builder().setAlgorithm(DFA).build(); - public static final Options RUN_WITH_NFA = Options.builder().setAlgorithm(NFA).build(); + public static final Options RUN_WITH_DFA = Options.builder().setAlgorithm(Options.Algorithm.DFA).build(); + public static final Options RUN_WITH_NFA = Options.builder().setAlgorithm(Options.Algorithm.NFA).build(); protected final Options options; diff --git a/javatests/com/google/re2j/ParserTest.java b/javatests/io/trino/re2j/ParserTest.java similarity index 94% rename from javatests/com/google/re2j/ParserTest.java rename to javatests/io/trino/re2j/ParserTest.java index 046c3374..f989d87a 100644 --- a/javatests/com/google/re2j/ParserTest.java +++ b/javatests/io/trino/re2j/ParserTest.java @@ -5,17 +5,8 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/parse_test.go -package com.google.re2j; - -import static com.google.re2j.RE2.FOLD_CASE; -import static com.google.re2j.RE2.LITERAL; -import static com.google.re2j.RE2.MATCH_NL; -import static com.google.re2j.RE2.NON_GREEDY; -import static com.google.re2j.RE2.PERL; -import static com.google.re2j.RE2.PERL_X; -import static com.google.re2j.RE2.POSIX; -import static com.google.re2j.RE2.UNICODE_GROUPS; -import static com.google.re2j.RE2.WAS_DOLLAR; +package io.trino.re2j; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -78,7 +69,7 @@ public boolean applies(int r) { OP_NAMES.put(Regexp.Op.ALTERNATE, "alt"); } - private static final int TEST_FLAGS = MATCH_NL | PERL_X | UNICODE_GROUPS; + private static final int TEST_FLAGS = RE2.MATCH_NL | RE2.PERL_X | RE2.UNICODE_GROUPS; private static final String[][] PARSE_TESTS = { // Base cases @@ -297,7 +288,7 @@ public void testParseSimple() throws Exception { @Test public void testParseFoldCase() { - testParseDump(FOLDCASE_TESTS, FOLD_CASE); + testParseDump(FOLDCASE_TESTS, RE2.FOLD_CASE); } private static final String[][] LITERAL_TESTS = { @@ -306,7 +297,7 @@ public void testParseFoldCase() { @Test public void testParseLiteral() { - testParseDump(LITERAL_TESTS, LITERAL); + testParseDump(LITERAL_TESTS, RE2.LITERAL); } private static final String[][] MATCHNL_TESTS = { @@ -318,7 +309,7 @@ public void testParseLiteral() { @Test public void testParseMatchNL() { - testParseDump(MATCHNL_TESTS, MATCH_NL); + testParseDump(MATCHNL_TESTS, RE2.MATCH_NL); } private static final String[][] NOMATCHNL_TESTS = { @@ -370,7 +361,7 @@ private static void dumpRegexp(StringBuilder b, Regexp re) { case PLUS: case QUEST: case REPEAT: - if ((re.flags & NON_GREEDY) != 0) { + if ((re.flags & RE2.NON_GREEDY) != 0) { b.append('n'); } b.append(name); @@ -381,7 +372,7 @@ private static void dumpRegexp(StringBuilder b, Regexp re) { } else { b.append("lit"); } - if ((re.flags & FOLD_CASE) != 0) { + if ((re.flags & RE2.FOLD_CASE) != 0) { for (int r : re.runes) { if (Unicode.simpleFold(r) != r) { b.append("fold"); @@ -398,7 +389,7 @@ private static void dumpRegexp(StringBuilder b, Regexp re) { b.append('{'); switch (re.op) { case END_TEXT: - if ((re.flags & WAS_DOLLAR) == 0) { + if ((re.flags & RE2.WAS_DOLLAR) == 0) { b.append("\\z"); } break; @@ -553,14 +544,14 @@ private static String runesToString(int[] runes) { public void testParseInvalidRegexps() throws PatternSyntaxException { for (String regexp : INVALID_REGEXPS) { try { - Regexp re = Parser.parse(regexp, PERL); + Regexp re = Parser.parse(regexp, RE2.PERL); fail("Parsing (PERL) " + regexp + " should have failed, instead got " + dump(re)); } catch (PatternSyntaxException e) { /* ok */ } try { - Regexp re = Parser.parse(regexp, POSIX); + Regexp re = Parser.parse(regexp, RE2.POSIX); fail("parsing (POSIX) " + regexp + " should have failed, instead got " + dump(re)); } catch (PatternSyntaxException e) { @@ -568,9 +559,9 @@ public void testParseInvalidRegexps() throws PatternSyntaxException { } } for (String regexp : ONLY_PERL) { - Parser.parse(regexp, PERL); + Parser.parse(regexp, RE2.PERL); try { - Regexp re = Parser.parse(regexp, POSIX); + Regexp re = Parser.parse(regexp, RE2.POSIX); fail("parsing (POSIX) " + regexp + " should have failed, instead got " + dump(re)); } catch (PatternSyntaxException e) { @@ -579,13 +570,13 @@ public void testParseInvalidRegexps() throws PatternSyntaxException { } for (String regexp : ONLY_POSIX) { try { - Regexp re = Parser.parse(regexp, PERL); + Regexp re = Parser.parse(regexp, RE2.PERL); fail("parsing (PERL) " + regexp + " should have failed, instead got " + dump(re)); } catch (PatternSyntaxException e) { /* ok */ } - Parser.parse(regexp, POSIX); + Parser.parse(regexp, RE2.POSIX); } } diff --git a/javatests/com/google/re2j/PatternTest.java b/javatests/io/trino/re2j/PatternTest.java similarity index 99% rename from javatests/com/google/re2j/PatternTest.java rename to javatests/io/trino/re2j/PatternTest.java index a25e03bd..d4f72a67 100644 --- a/javatests/com/google/re2j/PatternTest.java +++ b/javatests/io/trino/re2j/PatternTest.java @@ -1,6 +1,6 @@ // Copyright 2012 Google Inc. All Rights Reserved. -package com.google.re2j; +package io.trino.re2j; import org.junit.Test; import org.junit.experimental.runners.Enclosed; diff --git a/javatests/com/google/re2j/ProgTest.java b/javatests/io/trino/re2j/ProgTest.java similarity index 99% rename from javatests/com/google/re2j/ProgTest.java rename to javatests/io/trino/re2j/ProgTest.java index 86f92565..a83bfb09 100644 --- a/javatests/com/google/re2j/ProgTest.java +++ b/javatests/io/trino/re2j/ProgTest.java @@ -5,7 +5,7 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/prog_test.go -package com.google.re2j; +package io.trino.re2j; import org.junit.Test; diff --git a/javatests/com/google/re2j/RE2CompileTest.java b/javatests/io/trino/re2j/RE2CompileTest.java similarity index 94% rename from javatests/com/google/re2j/RE2CompileTest.java rename to javatests/io/trino/re2j/RE2CompileTest.java index 07b1bf86..149114d8 100644 --- a/javatests/com/google/re2j/RE2CompileTest.java +++ b/javatests/io/trino/re2j/RE2CompileTest.java @@ -1,6 +1,5 @@ -package com.google.re2j; +package io.trino.re2j; -import static com.google.re2j.Options.DEFAULT_OPTIONS; import static org.junit.Assert.fail; import org.junit.Test; @@ -59,7 +58,7 @@ public RE2CompileTest(String input, String expectedError) { @Test public void testCompile() { try { - RE2.compile(input, DEFAULT_OPTIONS); + RE2.compile(input, Options.DEFAULT_OPTIONS); if (expectedError != null) { fail("RE2.compile(" + input + ") was successful, expected " + expectedError); } diff --git a/javatests/com/google/re2j/RE2MatchTest.java b/javatests/io/trino/re2j/RE2MatchTest.java similarity index 98% rename from javatests/com/google/re2j/RE2MatchTest.java rename to javatests/io/trino/re2j/RE2MatchTest.java index 3e912b49..85748698 100644 --- a/javatests/com/google/re2j/RE2MatchTest.java +++ b/javatests/io/trino/re2j/RE2MatchTest.java @@ -1,4 +1,4 @@ -package com.google.re2j; +package io.trino.re2j; import org.junit.Test; import org.junit.experimental.runners.Enclosed; diff --git a/javatests/com/google/re2j/RE2QuoteMetaTest.java b/javatests/io/trino/re2j/RE2QuoteMetaTest.java similarity index 93% rename from javatests/com/google/re2j/RE2QuoteMetaTest.java rename to javatests/io/trino/re2j/RE2QuoteMetaTest.java index cce4bd87..1d48d0c5 100644 --- a/javatests/com/google/re2j/RE2QuoteMetaTest.java +++ b/javatests/io/trino/re2j/RE2QuoteMetaTest.java @@ -1,6 +1,5 @@ -package com.google.re2j; +package io.trino.re2j; -import static com.google.re2j.Options.DEFAULT_OPTIONS; import static io.airlift.slice.Slices.utf8Slice; import static org.junit.Assert.fail; @@ -55,7 +54,7 @@ public void testQuoteMeta() { if (!pattern.isEmpty()) { RE2 re = null; try { - re = RE2.compile(quoted, DEFAULT_OPTIONS); + re = RE2.compile(quoted, Options.DEFAULT_OPTIONS); } catch (PatternSyntaxException e) { fail(String.format("Unexpected error compiling quoteMeta(\"%s\"): %s", pattern, e.getMessage())); @@ -74,7 +73,7 @@ public void testQuoteMeta() { @Test public void testLiteralPrefix() throws PatternSyntaxException { // Literal method needs to scan the pattern. - RE2 re = RE2.compile(pattern, DEFAULT_OPTIONS); + RE2 re = RE2.compile(pattern, Options.DEFAULT_OPTIONS); if (re.prefixComplete != isLiteral) { fail(String.format("literalPrefix(\"%s\") = %s; want %s", pattern, re.prefixComplete, isLiteral)); } diff --git a/javatests/com/google/re2j/RE2ReplaceAllFunctionTest.java b/javatests/io/trino/re2j/RE2ReplaceAllFunctionTest.java similarity index 99% rename from javatests/com/google/re2j/RE2ReplaceAllFunctionTest.java rename to javatests/io/trino/re2j/RE2ReplaceAllFunctionTest.java index 4d898332..5b916b6c 100644 --- a/javatests/com/google/re2j/RE2ReplaceAllFunctionTest.java +++ b/javatests/io/trino/re2j/RE2ReplaceAllFunctionTest.java @@ -1,4 +1,4 @@ -package com.google.re2j; +package io.trino.re2j; import org.junit.Test; import org.junit.experimental.runners.Enclosed; diff --git a/javatests/com/google/re2j/RE2ReplaceTest.java b/javatests/io/trino/re2j/RE2ReplaceTest.java similarity index 99% rename from javatests/com/google/re2j/RE2ReplaceTest.java rename to javatests/io/trino/re2j/RE2ReplaceTest.java index e72479dd..95798654 100644 --- a/javatests/com/google/re2j/RE2ReplaceTest.java +++ b/javatests/io/trino/re2j/RE2ReplaceTest.java @@ -1,4 +1,4 @@ -package com.google.re2j; +package io.trino.re2j; import org.junit.Test; import org.junit.experimental.runners.Enclosed; diff --git a/javatests/com/google/re2j/RE2Test.java b/javatests/io/trino/re2j/RE2Test.java similarity index 78% rename from javatests/com/google/re2j/RE2Test.java rename to javatests/io/trino/re2j/RE2Test.java index 5f5dce09..f1ebf745 100644 --- a/javatests/com/google/re2j/RE2Test.java +++ b/javatests/io/trino/re2j/RE2Test.java @@ -5,14 +5,12 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/all_test.go -package com.google.re2j; +package io.trino.re2j; import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; -import static com.google.re2j.RE2.Anchor.ANCHOR_BOTH; -import static com.google.re2j.RE2.Anchor.UNANCHORED; import static io.airlift.slice.Slices.utf8Slice; import static org.junit.Assert.assertEquals; @@ -44,22 +42,22 @@ protected RE2TestBase(Options options) { @Test public void testFullMatch() { assertEquals(true, RE2.compile("ab+c", options).match( - utf8Slice("abbbbbc"), 0, ANCHOR_BOTH, null, 0)); + utf8Slice("abbbbbc"), 0, RE2.Anchor.ANCHOR_BOTH, null, 0)); assertEquals(false, RE2.compile("ab+c", options).match( - utf8Slice("xabbbbbc"), 0, ANCHOR_BOTH, null, 0)); + utf8Slice("xabbbbbc"), 0, RE2.Anchor.ANCHOR_BOTH, null, 0)); } @Test public void testFindEnd() { RE2 r = RE2.compile("abc.*def", options); assertEquals(true, r.match(utf8Slice("yyyabcxxxdefzzz"), - 0, UNANCHORED, null, 0)); + 0, RE2.Anchor.UNANCHORED, null, 0)); assertEquals(true, r.match(utf8Slice("yyyabcxxxdefzzz"), - 3, UNANCHORED, null, 0)); + 3, RE2.Anchor.UNANCHORED, null, 0)); assertEquals(false, r.match(utf8Slice("yyyabcxxxdefzzz"), - 4, UNANCHORED, null, 0)); + 4, RE2.Anchor.UNANCHORED, null, 0)); assertEquals(false, r.match(utf8Slice("abcxxxde"), - 3, UNANCHORED, null, 0)); + 3, RE2.Anchor.UNANCHORED, null, 0)); } } } diff --git a/javatests/com/google/re2j/RE2TestNumSubexps.java b/javatests/io/trino/re2j/RE2TestNumSubexps.java similarity index 86% rename from javatests/com/google/re2j/RE2TestNumSubexps.java rename to javatests/io/trino/re2j/RE2TestNumSubexps.java index 42cf2ef4..dd3ac322 100644 --- a/javatests/com/google/re2j/RE2TestNumSubexps.java +++ b/javatests/io/trino/re2j/RE2TestNumSubexps.java @@ -1,6 +1,5 @@ -package com.google.re2j; +package io.trino.re2j; -import static com.google.re2j.Options.DEFAULT_OPTIONS; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -38,6 +37,6 @@ public RE2TestNumSubexps(String input, String expected) { @Test public void testNumSubexp() throws PatternSyntaxException { - assertEquals("numberOfCapturingGroups(" + input +")", expected, RE2.compile(input, DEFAULT_OPTIONS).numberOfCapturingGroups()); + assertEquals("numberOfCapturingGroups(" + input +")", expected, RE2.compile(input, Options.DEFAULT_OPTIONS).numberOfCapturingGroups()); } } diff --git a/javatests/com/google/re2j/SimplifyTest.java b/javatests/io/trino/re2j/SimplifyTest.java similarity index 99% rename from javatests/com/google/re2j/SimplifyTest.java rename to javatests/io/trino/re2j/SimplifyTest.java index 45911ab5..1618abdd 100644 --- a/javatests/com/google/re2j/SimplifyTest.java +++ b/javatests/io/trino/re2j/SimplifyTest.java @@ -5,7 +5,7 @@ // Original Go source here: // http://code.google.com/p/go/source/browse/src/pkg/regexp/syntax/simplify_test.go -package com.google.re2j; +package io.trino.re2j; import static org.junit.Assert.assertEquals; diff --git a/javatests/com/google/re2j/Strconv.java b/javatests/io/trino/re2j/Strconv.java similarity index 99% rename from javatests/com/google/re2j/Strconv.java rename to javatests/io/trino/re2j/Strconv.java index f9db5720..e94b3169 100644 --- a/javatests/com/google/re2j/Strconv.java +++ b/javatests/io/trino/re2j/Strconv.java @@ -8,7 +8,7 @@ // While this is a port of production Go source, it is currently // only used by ExecTest, which is why it appears beneath javatests/. -package com.google.re2j; +package io.trino.re2j; class Strconv { diff --git a/javatests/com/google/re2j/StrconvTest.java b/javatests/io/trino/re2j/StrconvTest.java similarity index 98% rename from javatests/com/google/re2j/StrconvTest.java rename to javatests/io/trino/re2j/StrconvTest.java index 3e76cba1..a5504810 100644 --- a/javatests/com/google/re2j/StrconvTest.java +++ b/javatests/io/trino/re2j/StrconvTest.java @@ -4,7 +4,7 @@ // Derived from http://golang.org/src/pkg/strconv/quote_test.go. -package com.google.re2j; +package io.trino.re2j; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; diff --git a/javatests/com/google/re2j/UNIXBufferedReader.java b/javatests/io/trino/re2j/UNIXBufferedReader.java similarity index 99% rename from javatests/com/google/re2j/UNIXBufferedReader.java rename to javatests/io/trino/re2j/UNIXBufferedReader.java index 4abfcde1..f453ceeb 100644 --- a/javatests/com/google/re2j/UNIXBufferedReader.java +++ b/javatests/io/trino/re2j/UNIXBufferedReader.java @@ -1,6 +1,6 @@ // Copyright 2012 Google Inc. All Rights Reserved. -package com.google.re2j; +package io.trino.re2j; import java.io.IOException; import java.io.Reader; diff --git a/javatests/com/google/re2j/UnicodeTest.java b/javatests/io/trino/re2j/UnicodeTest.java similarity index 97% rename from javatests/com/google/re2j/UnicodeTest.java rename to javatests/io/trino/re2j/UnicodeTest.java index 0ae11b29..3ed15155 100644 --- a/javatests/com/google/re2j/UnicodeTest.java +++ b/javatests/io/trino/re2j/UnicodeTest.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package com.google.re2j; +package io.trino.re2j; import static org.junit.Assert.fail;