blob: b111ca37448563cbe7584f0763c011b80d9aff3c (
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
|
package bjc.utils.parserutils.splitterv2;
import bjc.utils.funcdata.IList;
import bjc.utils.functypes.ID;
import bjc.utils.ioutils.RegexStringEditor;
import java.util.regex.Pattern;
/**
* Splits a string into pieces around a regular expression.
*
* @author EVE
*
*/
public class SimpleTokenSplitter implements TokenSplitter {
protected Pattern spliter;
private boolean keepDelim;
/**
* Create a new simple token splitter.
*
* @param splitter
* The pattern to split around.
*
* @param keepDelims
* Whether or not delimiters should be kept.
*/
public SimpleTokenSplitter(Pattern splitter, boolean keepDelims) {
spliter = splitter;
keepDelim = keepDelims;
}
@Override
public IList<String> split(String input) {
if(keepDelim) {
return RegexStringEditor.mapOccurances(input, spliter, ID.id(), ID.id());
} else {
return RegexStringEditor.mapOccurances(input, spliter, ID.id(), strang -> "");
}
}
@Override
public String toString() {
return String.format("SimpleTokenSplitter [spliter=%s, keepDelim=%s]", spliter, keepDelim);
}
}
|