mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-05 00:56:42 +00:00
modify toml4j fork to automatically add new fields without overwriting previous ones and setup motd
This commit is contained in:
69
proxy/src/main/java/dev/plex/toml/Keys.java
Normal file
69
proxy/src/main/java/dev/plex/toml/Keys.java
Normal file
@ -0,0 +1,69 @@
|
||||
package dev.plex.toml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Keys {
|
||||
|
||||
static class Key {
|
||||
final String name;
|
||||
final int index;
|
||||
final String path;
|
||||
|
||||
Key(String name, int index, Key next) {
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
if (next != null) {
|
||||
this.path = name + "." + next.path;
|
||||
} else {
|
||||
this.path = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Key[] split(String key) {
|
||||
List<Key> splitKey = new ArrayList<Key>();
|
||||
StringBuilder current = new StringBuilder();
|
||||
boolean quoted = false;
|
||||
boolean indexable = true;
|
||||
boolean inIndex = false;
|
||||
int index = -1;
|
||||
|
||||
for (int i = key.length() - 1; i > -1; i--) {
|
||||
char c = key.charAt(i);
|
||||
if (c == ']' && indexable) {
|
||||
inIndex = true;
|
||||
continue;
|
||||
}
|
||||
indexable = false;
|
||||
if (c == '[' && inIndex) {
|
||||
inIndex = false;
|
||||
index = Integer.parseInt(current.toString());
|
||||
current = new StringBuilder();
|
||||
continue;
|
||||
}
|
||||
if (isQuote(c) && (i == 0 || key.charAt(i - 1) != '\\')) {
|
||||
quoted = !quoted;
|
||||
indexable = false;
|
||||
}
|
||||
if (c != '.' || quoted) {
|
||||
current.insert(0, c);
|
||||
} else {
|
||||
splitKey.add(0, new Key(current.toString(), index, !splitKey.isEmpty() ? splitKey.get(0) : null));
|
||||
indexable = true;
|
||||
index = -1;
|
||||
current = new StringBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
splitKey.add(0, new Key(current.toString(), index, !splitKey.isEmpty() ? splitKey.get(0) : null));
|
||||
|
||||
return splitKey.toArray(new Key[0]);
|
||||
}
|
||||
|
||||
static boolean isQuote(char c) {
|
||||
return c == '"' || c == '\'';
|
||||
}
|
||||
|
||||
private Keys() {}
|
||||
}
|
Reference in New Issue
Block a user