blob: 1d6d0a2b310e2785bed93965459b899987cef2a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
package bjc.utils.parserutils.splitter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
/**
* Implementation of a splitter that runs in two passes.
*
* This is useful because {@link SimpleTokenSplitter} doesn't like handling both
* <= and = without mangling them.
*
* The first pass splits on compound operators, which are built up from simple
* operators.
*
* The second pass removes simple operators.
*
* @author EVE
*
*/
@Deprecated
public class TwoLevelSplitter implements TokenSplitter {
private SimpleTokenSplitter high;
private SimpleTokenSplitter low;
/**
* Create a new two level splitter.
*/
public TwoLevelSplitter() {
high = new SimpleTokenSplitter();
low = new SimpleTokenSplitter();
}
@Override
public String[] split(String inp) {
List<String> ret = new ArrayList<>();
String[] partials = high.split(inp);
for(String partial : partials) {
String[] finals = low.split(partial);
for(String fin : finals) {
ret.add(fin);
}
}
return ret.toArray(new String[ret.size()]);
}
/**
* Adds compound operators to split on.
*
* @param delims
* The compound operators to split on.
*/
public void addCompoundDelim(String... delims) {
for(String delim : delims) {
high.addDelimiter(delim);
low.addNonMatcher(Pattern.quote(delim));
}
}
/**
* Adds simple operators to split on.
*
* @param delims
* The simple operators to split on.
*/
public void addSimpleDelim(String... delims) {
for(String delim : delims) {
low.addDelimiter(delim);
}
}
/**
* Adds repeated compound operators to split on.
*
* @param delims
* The repeated compound operators to split on.
*/
public void addCompoundMulti(String... delims) {
for(String delim : delims) {
high.addMultiDelimiter(delim);
low.addNonMatcher("(?:" + delim + ")+");
}
}
/**
* Adds simple compound operators to split on.
*
* @param delims
* The repeated simple operators to split on.
*/
public void addSimpleMulti(String... delims) {
for(String delim : delims) {
low.addMultiDelimiter(delim);
}
}
/**
* Exclude strings matching a regex from both splits.
*
* @param exclusions
* The regexes to exclude matches for.
*/
public void exclude(String... exclusions) {
for(String exclusion : exclusions) {
high.addNonMatcher(exclusion);
low.addNonMatcher(exclusion);
}
}
/**
* Ready the splitter for use.
*/
public void compile() {
high.compile();
low.compile();
}
}
|