-
Notifications
You must be signed in to change notification settings - Fork 11
/
YamlSectionWalker.java
56 lines (42 loc) · 1.32 KB
/
YamlSectionWalker.java
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
package eu.okaeri.configs.postprocessor.format;
import eu.okaeri.configs.postprocessor.ConfigSectionWalker;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public abstract class YamlSectionWalker implements ConfigSectionWalker {
private static final Set<String> MULTILINE_START = new HashSet<>(Arrays.asList(
">",
">-",
"|",
"|-"
));
@Override
public boolean isKeyMultilineStart(String line) {
String trimmed = line.trim().replaceAll("\\s{2,}", " ");
if (trimmed.isEmpty()) {
return false;
}
int colon = trimmed.indexOf(":");
int distance = trimmed.length() - colon;
for (String trigger : MULTILINE_START) {
// offset by 2 due to ': ' before the trigger
if (distance > (trigger.length() + 2)) {
continue;
}
if (!trimmed.endsWith(trigger)) {
continue;
}
return true;
}
return false;
}
@Override
public boolean isKey(String line) {
String name = this.readName(line);
return !name.isEmpty() && (name.charAt(0) != '-') && (name.charAt(0) != '#');
}
@Override
public String readName(String line) {
return line.split(":", 2)[0].trim();
}
}