mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 09:07:37 +00:00
move this back
This commit is contained in:
parent
de13860741
commit
a24aa6a962
@ -1,11 +1,11 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import static dev.plex.toml.ValueWriters.WRITERS;
|
||||
import static com.moandjiezana.toml.ValueWriters.WRITERS;
|
||||
|
||||
public abstract class ArrayValueWriter implements ValueWriter {
|
||||
static protected boolean isArrayish(Object value) {
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
@ -1,19 +1,19 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Context {
|
||||
final dev.plex.toml.Identifier identifier;
|
||||
final Identifier identifier;
|
||||
final AtomicInteger line;
|
||||
final Results.Errors errors;
|
||||
|
||||
public Context(dev.plex.toml.Identifier identifier, AtomicInteger line, Results.Errors errors) {
|
||||
public Context(Identifier identifier, AtomicInteger line, Results.Errors errors) {
|
||||
this.identifier = identifier;
|
||||
this.line = line;
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public Context with(dev.plex.toml.Identifier identifier) {
|
||||
public Context with(Identifier identifier) {
|
||||
return new Context(identifier, line, errors);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
public class Identifier
|
||||
{
|
||||
@ -170,7 +170,7 @@ public class Identifier
|
||||
break;
|
||||
}
|
||||
|
||||
if (dev.plex.toml.Keys.isQuote(c))
|
||||
if (Keys.isQuote(c))
|
||||
{
|
||||
if (!quoteAllowed)
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@ -6,7 +6,7 @@ public class IdentifierConverter {
|
||||
|
||||
static final IdentifierConverter IDENTIFIER_CONVERTER = new IdentifierConverter();
|
||||
|
||||
dev.plex.toml.Identifier convert(String s, AtomicInteger index, dev.plex.toml.Context context) {
|
||||
Identifier convert(String s, AtomicInteger index, Context context) {
|
||||
boolean quoted = false;
|
||||
StringBuilder name = new StringBuilder();
|
||||
boolean terminated = false;
|
||||
@ -16,7 +16,7 @@ public class IdentifierConverter {
|
||||
|
||||
for (int i = index.get(); i < s.length(); i = index.incrementAndGet()) {
|
||||
char c = s.charAt(i);
|
||||
if (dev.plex.toml.Keys.isQuote(c) && (i == 0 || s.charAt(i - 1) != '\\')) {
|
||||
if (Keys.isQuote(c) && (i == 0 || s.charAt(i - 1) != '\\')) {
|
||||
quoted = !quoted;
|
||||
name.append(c);
|
||||
} else if (c == '\n') {
|
||||
@ -52,10 +52,10 @@ public class IdentifierConverter {
|
||||
context.errors.invalidKey(name.toString(), context.line.get());
|
||||
}
|
||||
|
||||
return dev.plex.toml.Identifier.INVALID;
|
||||
return Identifier.INVALID;
|
||||
}
|
||||
|
||||
return dev.plex.toml.Identifier.from(name.toString(), context);
|
||||
return Identifier.from(name.toString(), context);
|
||||
}
|
||||
|
||||
private IdentifierConverter() {}
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
/**
|
||||
* Controls how a {@link TomlWriter} indents tables and key/value pairs.
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -28,7 +28,7 @@ class InlineTableValueReader implements ValueReader {
|
||||
char c = s.charAt(i);
|
||||
|
||||
if (inValue && !Character.isWhitespace(c)) {
|
||||
Object converted = ValueReaders.VALUE_READERS.convert(s, sharedIndex, context.with(dev.plex.toml.Identifier.from(currentKey.toString(), context)));
|
||||
Object converted = ValueReaders.VALUE_READERS.convert(s, sharedIndex, context.with(Identifier.from(currentKey.toString(), context)));
|
||||
|
||||
if (converted instanceof Results.Errors) {
|
||||
errors.add((Results.Errors) converted);
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
@ -1,8 +1,8 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class LiteralStringValueReader implements dev.plex.toml.ValueReader
|
||||
public class LiteralStringValueReader implements ValueReader
|
||||
{
|
||||
public static final LiteralStringValueReader LITERAL_STRING_VALUE_READER = new LiteralStringValueReader();
|
||||
@Override
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
@ -29,7 +29,7 @@ class MapValueWriter implements ValueWriter
|
||||
|
||||
Map<?, ?> from = (Map<?, ?>) value;
|
||||
|
||||
dev.plex.toml.Toml toml = null;
|
||||
Toml toml = null;
|
||||
|
||||
if (file != null)
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
class MultilineLiteralStringValueReader implements dev.plex.toml.ValueReader
|
||||
class MultilineLiteralStringValueReader implements ValueReader
|
||||
{
|
||||
|
||||
static final MultilineLiteralStringValueReader MULTILINE_LITERAL_STRING_VALUE_READER = new MultilineLiteralStringValueReader();
|
||||
@ -13,7 +13,7 @@ class MultilineLiteralStringValueReader implements dev.plex.toml.ValueReader
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context) {
|
||||
public Object read(String s, AtomicInteger index, Context context) {
|
||||
AtomicInteger line = context.line;
|
||||
int startLine = line.get();
|
||||
int originalStartIndex = index.get();
|
@ -1,8 +1,8 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
class MultilineStringValueReader implements dev.plex.toml.ValueReader
|
||||
class MultilineStringValueReader implements ValueReader
|
||||
{
|
||||
|
||||
static final MultilineStringValueReader MULTILINE_STRING_VALUE_READER = new MultilineStringValueReader();
|
||||
@ -13,7 +13,7 @@ class MultilineStringValueReader implements dev.plex.toml.ValueReader
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(String s, AtomicInteger index, dev.plex.toml.Context context) {
|
||||
public Object read(String s, AtomicInteger index, Context context) {
|
||||
AtomicInteger line = context.line;
|
||||
int startLine = line.get();
|
||||
int originalStartIndex = index.get();
|
||||
@ -38,15 +38,15 @@ class MultilineStringValueReader implements dev.plex.toml.ValueReader
|
||||
}
|
||||
|
||||
if (endIndex == -1) {
|
||||
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||
Results.Errors errors = new Results.Errors();
|
||||
errors.unterminated(context.identifier.getName(), s.substring(originalStartIndex), startLine);
|
||||
return errors;
|
||||
}
|
||||
|
||||
s = s.substring(startIndex, endIndex);
|
||||
s = s.replaceAll("\\\\\\s+", "");
|
||||
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceUnicodeCharacters(s);
|
||||
s = dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceSpecialCharacters(s);
|
||||
s = StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceUnicodeCharacters(s);
|
||||
s = StringValueReaderWriter.STRING_VALUE_READER_WRITER.replaceSpecialCharacters(s);
|
||||
|
||||
return s;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
@ -1,14 +1,14 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
|
||||
import static dev.plex.toml.MapValueWriter.MAP_VALUE_WRITER;
|
||||
import static com.moandjiezana.toml.MapValueWriter.MAP_VALUE_WRITER;
|
||||
|
||||
class ObjectValueWriter implements dev.plex.toml.ValueWriter
|
||||
class ObjectValueWriter implements ValueWriter
|
||||
{
|
||||
static final dev.plex.toml.ValueWriter OBJECT_VALUE_WRITER = new ObjectValueWriter();
|
||||
static final ValueWriter OBJECT_VALUE_WRITER = new ObjectValueWriter();
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Object value) {
|
||||
@ -16,7 +16,7 @@ class ObjectValueWriter implements dev.plex.toml.ValueWriter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Object value, dev.plex.toml.WriterContext context) {
|
||||
public void write(Object value, WriterContext context) {
|
||||
Map<String, Object> to = new LinkedHashMap<String, Object>();
|
||||
Set<Field> fields = getFields(value.getClass());
|
||||
for (Field field : fields) {
|
@ -1,10 +1,10 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static dev.plex.toml.ValueWriters.WRITERS;
|
||||
import static com.moandjiezana.toml.ValueWriters.WRITERS;
|
||||
|
||||
class PrimitiveArrayValueWriter extends dev.plex.toml.ArrayValueWriter
|
||||
class PrimitiveArrayValueWriter extends ArrayValueWriter
|
||||
{
|
||||
static final ValueWriter PRIMITIVE_ARRAY_VALUE_WRITER = new PrimitiveArrayValueWriter();
|
||||
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -55,7 +55,7 @@ class Results {
|
||||
.append(key);
|
||||
}
|
||||
|
||||
void invalidTextAfterIdentifier(dev.plex.toml.Identifier identifier, char text, int line) {
|
||||
void invalidTextAfterIdentifier(Identifier identifier, char text, int line) {
|
||||
sb.append("Invalid text after key ")
|
||||
.append(identifier.getName())
|
||||
.append(" on line ")
|
||||
@ -124,23 +124,23 @@ class Results {
|
||||
|
||||
final Errors errors = new Errors();
|
||||
private final Set<String> tables = new HashSet<String>();
|
||||
private final Deque<dev.plex.toml.Container> stack = new ArrayDeque<dev.plex.toml.Container>();
|
||||
private final Deque<Container> stack = new ArrayDeque<Container>();
|
||||
|
||||
Results() {
|
||||
stack.push(new dev.plex.toml.Container.Table(""));
|
||||
stack.push(new Container.Table(""));
|
||||
}
|
||||
|
||||
void addValue(String key, Object value, AtomicInteger line) {
|
||||
dev.plex.toml.Container currentTable = stack.peek();
|
||||
Container currentTable = stack.peek();
|
||||
|
||||
if (value instanceof Map) {
|
||||
String path = getInlineTablePath(key);
|
||||
if (path == null) {
|
||||
startTable(key, line);
|
||||
} else if (path.isEmpty()) {
|
||||
startTables(dev.plex.toml.Identifier.from(key, null), line);
|
||||
startTables(Identifier.from(key, null), line);
|
||||
} else {
|
||||
startTables(dev.plex.toml.Identifier.from(path, null), line);
|
||||
startTables(Identifier.from(path, null), line);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> valueMap = (Map<String, Object>) value;
|
||||
@ -151,7 +151,7 @@ class Results {
|
||||
} else if (currentTable.accepts(key)) {
|
||||
currentTable.put(key, value);
|
||||
} else {
|
||||
if (currentTable.get(key) instanceof dev.plex.toml.Container) {
|
||||
if (currentTable.get(key) instanceof Container) {
|
||||
errors.keyDuplicatesTable(key, line);
|
||||
} else {
|
||||
errors.duplicateKey(key, line != null ? line.get() : -1);
|
||||
@ -159,37 +159,37 @@ class Results {
|
||||
}
|
||||
}
|
||||
|
||||
void startTableArray(dev.plex.toml.Identifier identifier, AtomicInteger line) {
|
||||
void startTableArray(Identifier identifier, AtomicInteger line) {
|
||||
String tableName = identifier.getBareName();
|
||||
while (stack.size() > 1) {
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
dev.plex.toml.Keys.Key[] tableParts = dev.plex.toml.Keys.split(tableName);
|
||||
Keys.Key[] tableParts = Keys.split(tableName);
|
||||
for (int i = 0; i < tableParts.length; i++) {
|
||||
String tablePart = tableParts[i].name;
|
||||
dev.plex.toml.Container currentContainer = stack.peek();
|
||||
Container currentContainer = stack.peek();
|
||||
|
||||
if (currentContainer.get(tablePart) instanceof dev.plex.toml.Container.TableArray) {
|
||||
dev.plex.toml.Container.TableArray currentTableArray = (dev.plex.toml.Container.TableArray) currentContainer.get(tablePart);
|
||||
if (currentContainer.get(tablePart) instanceof Container.TableArray) {
|
||||
Container.TableArray currentTableArray = (Container.TableArray) currentContainer.get(tablePart);
|
||||
stack.push(currentTableArray);
|
||||
|
||||
if (i == tableParts.length - 1) {
|
||||
currentTableArray.put(tablePart, new dev.plex.toml.Container.Table());
|
||||
currentTableArray.put(tablePart, new Container.Table());
|
||||
}
|
||||
|
||||
stack.push(currentTableArray.getCurrent());
|
||||
currentContainer = stack.peek();
|
||||
} else if (currentContainer.get(tablePart) instanceof dev.plex.toml.Container.Table && i < tableParts.length - 1) {
|
||||
dev.plex.toml.Container nextTable = (dev.plex.toml.Container) currentContainer.get(tablePart);
|
||||
} else if (currentContainer.get(tablePart) instanceof Container.Table && i < tableParts.length - 1) {
|
||||
Container nextTable = (Container) currentContainer.get(tablePart);
|
||||
stack.push(nextTable);
|
||||
} else if (currentContainer.accepts(tablePart)) {
|
||||
dev.plex.toml.Container newContainer = i == tableParts.length - 1 ? new dev.plex.toml.Container.TableArray() : new dev.plex.toml.Container.Table();
|
||||
Container newContainer = i == tableParts.length - 1 ? new Container.TableArray() : new Container.Table();
|
||||
addValue(tablePart, newContainer, line);
|
||||
stack.push(newContainer);
|
||||
|
||||
if (newContainer instanceof dev.plex.toml.Container.TableArray) {
|
||||
stack.push(((dev.plex.toml.Container.TableArray) newContainer).getCurrent());
|
||||
if (newContainer instanceof Container.TableArray) {
|
||||
stack.push(((Container.TableArray) newContainer).getCurrent());
|
||||
}
|
||||
} else {
|
||||
errors.duplicateTable(tableName, line.get());
|
||||
@ -198,26 +198,26 @@ class Results {
|
||||
}
|
||||
}
|
||||
|
||||
void startTables(dev.plex.toml.Identifier id, AtomicInteger line) {
|
||||
void startTables(Identifier id, AtomicInteger line) {
|
||||
String tableName = id.getBareName();
|
||||
|
||||
while (stack.size() > 1) {
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
dev.plex.toml.Keys.Key[] tableParts = dev.plex.toml.Keys.split(tableName);
|
||||
Keys.Key[] tableParts = Keys.split(tableName);
|
||||
for (int i = 0; i < tableParts.length; i++) {
|
||||
String tablePart = tableParts[i].name;
|
||||
dev.plex.toml.Container currentContainer = stack.peek();
|
||||
if (currentContainer.get(tablePart) instanceof dev.plex.toml.Container) {
|
||||
dev.plex.toml.Container nextTable = (dev.plex.toml.Container) currentContainer.get(tablePart);
|
||||
Container currentContainer = stack.peek();
|
||||
if (currentContainer.get(tablePart) instanceof Container) {
|
||||
Container nextTable = (Container) currentContainer.get(tablePart);
|
||||
if (i == tableParts.length - 1 && !nextTable.isImplicit()) {
|
||||
errors.duplicateTable(tableName, line.get());
|
||||
return;
|
||||
}
|
||||
stack.push(nextTable);
|
||||
if (stack.peek() instanceof dev.plex.toml.Container.TableArray) {
|
||||
stack.push(((dev.plex.toml.Container.TableArray) stack.peek()).getCurrent());
|
||||
if (stack.peek() instanceof Container.TableArray) {
|
||||
stack.push(((Container.TableArray) stack.peek()).getCurrent());
|
||||
}
|
||||
} else if (currentContainer.accepts(tablePart)) {
|
||||
startTable(tablePart, i < tableParts.length - 1, line);
|
||||
@ -232,22 +232,22 @@ class Results {
|
||||
* Warning: After this method has been called, this instance is no longer usable.
|
||||
*/
|
||||
Map<String, Object> consume() {
|
||||
dev.plex.toml.Container values = stack.getLast();
|
||||
Container values = stack.getLast();
|
||||
stack.clear();
|
||||
|
||||
return ((dev.plex.toml.Container.Table) values).consume();
|
||||
return ((Container.Table) values).consume();
|
||||
}
|
||||
|
||||
private dev.plex.toml.Container startTable(String tableName, AtomicInteger line) {
|
||||
dev.plex.toml.Container newTable = new dev.plex.toml.Container.Table(tableName);
|
||||
private Container startTable(String tableName, AtomicInteger line) {
|
||||
Container newTable = new Container.Table(tableName);
|
||||
addValue(tableName, newTable, line);
|
||||
stack.push(newTable);
|
||||
|
||||
return newTable;
|
||||
}
|
||||
|
||||
private dev.plex.toml.Container startTable(String tableName, boolean implicit, AtomicInteger line) {
|
||||
dev.plex.toml.Container newTable = new dev.plex.toml.Container.Table(tableName, implicit);
|
||||
private Container startTable(String tableName, boolean implicit, AtomicInteger line) {
|
||||
Container newTable = new Container.Table(tableName, implicit);
|
||||
addValue(tableName, newTable, line);
|
||||
stack.push(newTable);
|
||||
|
||||
@ -255,16 +255,16 @@ class Results {
|
||||
}
|
||||
|
||||
private String getInlineTablePath(String key) {
|
||||
Iterator<dev.plex.toml.Container> descendingIterator = stack.descendingIterator();
|
||||
Iterator<Container> descendingIterator = stack.descendingIterator();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
while (descendingIterator.hasNext()) {
|
||||
dev.plex.toml.Container next = descendingIterator.next();
|
||||
if (next instanceof dev.plex.toml.Container.TableArray) {
|
||||
Container next = descendingIterator.next();
|
||||
if (next instanceof Container.TableArray) {
|
||||
return null;
|
||||
}
|
||||
|
||||
dev.plex.toml.Container.Table table = (dev.plex.toml.Container.Table) next;
|
||||
Container.Table table = (Container.Table) next;
|
||||
|
||||
if (table.name == null) {
|
||||
break;
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
@ -6,7 +6,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class StringValueReaderWriter implements ValueReader, dev.plex.toml.ValueWriter
|
||||
class StringValueReaderWriter implements ValueReader, ValueWriter
|
||||
{
|
||||
|
||||
static final StringValueReaderWriter STRING_VALUE_READER_WRITER = new StringValueReaderWriter();
|
||||
@ -98,7 +98,7 @@ class StringValueReaderWriter implements ValueReader, dev.plex.toml.ValueWriter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Object value, dev.plex.toml.WriterContext context) {
|
||||
public void write(Object value, WriterContext context) {
|
||||
context.write('"');
|
||||
escapeUnicode(value.toString(), context);
|
||||
context.write('"');
|
||||
@ -109,7 +109,7 @@ class StringValueReaderWriter implements ValueReader, dev.plex.toml.ValueWriter
|
||||
return true;
|
||||
}
|
||||
|
||||
private void escapeUnicode(String in, dev.plex.toml.WriterContext context) {
|
||||
private void escapeUnicode(String in, WriterContext context) {
|
||||
for (int i = 0; i < in.length(); i++) {
|
||||
int codePoint = in.codePointAt(i);
|
||||
if (codePoint < specialCharacterEscapes.length && specialCharacterEscapes[codePoint] != null) {
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@ -14,7 +14,7 @@ class TomlParser {
|
||||
AtomicInteger index = new AtomicInteger();
|
||||
boolean inComment = false;
|
||||
AtomicInteger line = new AtomicInteger(1);
|
||||
dev.plex.toml.Identifier identifier = null;
|
||||
Identifier identifier = null;
|
||||
Object value = null;
|
||||
|
||||
for (int i = index.get(); i < tomlString.length(); i = index.incrementAndGet()) {
|
||||
@ -27,9 +27,9 @@ class TomlParser {
|
||||
if (c == '#' && !inComment) {
|
||||
inComment = true;
|
||||
} else if (!Character.isWhitespace(c) && !inComment && identifier == null) {
|
||||
dev.plex.toml.Identifier id = IdentifierConverter.IDENTIFIER_CONVERTER.convert(tomlString, index, new dev.plex.toml.Context(null, line, results.errors));
|
||||
Identifier id = IdentifierConverter.IDENTIFIER_CONVERTER.convert(tomlString, index, new Context(null, line, results.errors));
|
||||
|
||||
if (id != dev.plex.toml.Identifier.INVALID) {
|
||||
if (id != Identifier.INVALID) {
|
||||
if (id.isKey()) {
|
||||
identifier = id;
|
||||
} else if (id.isTable()) {
|
||||
@ -44,7 +44,7 @@ class TomlParser {
|
||||
value = null;
|
||||
line.incrementAndGet();
|
||||
} else if (!inComment && identifier != null && identifier.isKey() && value == null && !Character.isWhitespace(c)) {
|
||||
value = ValueReaders.VALUE_READERS.convert(tomlString, index, new dev.plex.toml.Context(identifier, line, results.errors));
|
||||
value = ValueReaders.VALUE_READERS.convert(tomlString, index, new Context(identifier, line, results.errors));
|
||||
|
||||
if (value instanceof Results.Errors) {
|
||||
results.errors.add((Results.Errors) value);
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -7,8 +7,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static dev.plex.toml.MapValueWriter.MAP_VALUE_WRITER;
|
||||
import static dev.plex.toml.ValueWriters.WRITERS;
|
||||
import static com.moandjiezana.toml.MapValueWriter.MAP_VALUE_WRITER;
|
||||
import static com.moandjiezana.toml.ValueWriters.WRITERS;
|
||||
|
||||
/**
|
||||
* <p>Converts Objects to TOML</p>
|
||||
@ -82,7 +82,7 @@ public class TomlWriter
|
||||
}
|
||||
}
|
||||
|
||||
private final dev.plex.toml.IndentationPolicy indentationPolicy;
|
||||
private final IndentationPolicy indentationPolicy;
|
||||
private final DatePolicy datePolicy;
|
||||
|
||||
/**
|
||||
@ -95,7 +95,7 @@ public class TomlWriter
|
||||
|
||||
private TomlWriter(int keyIndentation, int tableIndentation, int arrayDelimiterPadding, TimeZone timeZone, boolean showFractionalSeconds)
|
||||
{
|
||||
this.indentationPolicy = new dev.plex.toml.IndentationPolicy(keyIndentation, tableIndentation, arrayDelimiterPadding);
|
||||
this.indentationPolicy = new IndentationPolicy(keyIndentation, tableIndentation, arrayDelimiterPadding);
|
||||
this.datePolicy = new DatePolicy(timeZone, showFractionalSeconds);
|
||||
}
|
||||
|
37
proxy/src/main/java/com/moandjiezana/toml/ValueReaders.java
Normal file
37
proxy/src/main/java/com/moandjiezana/toml/ValueReaders.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.moandjiezana.toml.ArrayValueReader.ARRAY_VALUE_READER;
|
||||
import static com.moandjiezana.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER;
|
||||
import static com.moandjiezana.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER;
|
||||
import static com.moandjiezana.toml.InlineTableValueReader.INLINE_TABLE_VALUE_READER;
|
||||
import static com.moandjiezana.toml.LiteralStringValueReader.LITERAL_STRING_VALUE_READER;
|
||||
import static com.moandjiezana.toml.MultilineLiteralStringValueReader.MULTILINE_LITERAL_STRING_VALUE_READER;
|
||||
import static com.moandjiezana.toml.MultilineStringValueReader.MULTILINE_STRING_VALUE_READER;
|
||||
import static com.moandjiezana.toml.NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER;
|
||||
import static com.moandjiezana.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER;
|
||||
|
||||
class ValueReaders {
|
||||
|
||||
static final ValueReaders VALUE_READERS = new ValueReaders();
|
||||
|
||||
Object convert(String value, AtomicInteger index, Context context) {
|
||||
String substring = value.substring(index.get());
|
||||
for (ValueReader valueParser : READERS) {
|
||||
if (valueParser.canRead(substring)) {
|
||||
return valueParser.read(value, index, context);
|
||||
}
|
||||
}
|
||||
|
||||
Results.Errors errors = new Results.Errors();
|
||||
errors.invalidValue(context.identifier.getName(), substring, context.line.get());
|
||||
return errors;
|
||||
}
|
||||
|
||||
private ValueReaders() {}
|
||||
|
||||
private static final ValueReader[] READERS = {
|
||||
MULTILINE_STRING_VALUE_READER, MULTILINE_LITERAL_STRING_VALUE_READER, LITERAL_STRING_VALUE_READER, STRING_VALUE_READER_WRITER, DATE_VALUE_READER_WRITER, NUMBER_VALUE_READER_WRITER, BOOLEAN_VALUE_READER_WRITER, ARRAY_VALUE_READER, INLINE_TABLE_VALUE_READER
|
||||
};
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
interface ValueWriter {
|
||||
boolean canWrite(Object value);
|
||||
|
||||
void write(Object value, dev.plex.toml.WriterContext context);
|
||||
void write(Object value, WriterContext context);
|
||||
|
||||
boolean isPrimitiveType();
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import static dev.plex.toml.MapValueWriter.MAP_VALUE_WRITER;
|
||||
import static dev.plex.toml.NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER;
|
||||
import static com.moandjiezana.toml.MapValueWriter.MAP_VALUE_WRITER;
|
||||
import static com.moandjiezana.toml.NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER;
|
||||
|
||||
class ValueWriters {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package dev.plex.toml;
|
||||
package com.moandjiezana.toml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -14,14 +14,14 @@ class WriterContext
|
||||
private final String currentTableIndent;
|
||||
private final String currentFieldIndent;
|
||||
private final Writer output;
|
||||
private final dev.plex.toml.IndentationPolicy indentationPolicy;
|
||||
private final IndentationPolicy indentationPolicy;
|
||||
private final DatePolicy datePolicy;
|
||||
|
||||
public File file;
|
||||
public String parentName;
|
||||
public boolean hasRun = false;
|
||||
|
||||
WriterContext(dev.plex.toml.IndentationPolicy indentationPolicy, DatePolicy datePolicy, Writer output)
|
||||
WriterContext(IndentationPolicy indentationPolicy, DatePolicy datePolicy, Writer output)
|
||||
{
|
||||
this("", "", output, indentationPolicy, datePolicy);
|
||||
}
|
||||
@ -157,7 +157,7 @@ class WriterContext
|
||||
return key.isEmpty() ? arrayKey : key + "." + arrayKey;
|
||||
}
|
||||
|
||||
private String growIndent(dev.plex.toml.IndentationPolicy indentationPolicy)
|
||||
private String growIndent(IndentationPolicy indentationPolicy)
|
||||
{
|
||||
return currentTableIndent + fillStringWithSpaces(indentationPolicy.getTableIndent());
|
||||
}
|
||||
@ -170,7 +170,7 @@ class WriterContext
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
private WriterContext(String key, String tableIndent, Writer output, dev.plex.toml.IndentationPolicy indentationPolicy, DatePolicy datePolicy)
|
||||
private WriterContext(String key, String tableIndent, Writer output, IndentationPolicy indentationPolicy, DatePolicy datePolicy)
|
||||
{
|
||||
this.key = key;
|
||||
this.output = output;
|
@ -1,8 +1,8 @@
|
||||
package dev.plex.config;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.toml.Toml;
|
||||
import dev.plex.toml.TomlWriter;
|
||||
import com.moandjiezana.toml.Toml;
|
||||
import com.moandjiezana.toml.TomlWriter;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
package dev.plex.toml;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static dev.plex.toml.ArrayValueReader.ARRAY_VALUE_READER;
|
||||
import static dev.plex.toml.BooleanValueReaderWriter.BOOLEAN_VALUE_READER_WRITER;
|
||||
import static dev.plex.toml.DateValueReaderWriter.DATE_VALUE_READER_WRITER;
|
||||
import static dev.plex.toml.InlineTableValueReader.INLINE_TABLE_VALUE_READER;
|
||||
import static dev.plex.toml.LiteralStringValueReader.LITERAL_STRING_VALUE_READER;
|
||||
import static dev.plex.toml.MultilineLiteralStringValueReader.MULTILINE_LITERAL_STRING_VALUE_READER;
|
||||
import static dev.plex.toml.MultilineStringValueReader.MULTILINE_STRING_VALUE_READER;
|
||||
import static dev.plex.toml.NumberValueReaderWriter.NUMBER_VALUE_READER_WRITER;
|
||||
import static dev.plex.toml.StringValueReaderWriter.STRING_VALUE_READER_WRITER;
|
||||
|
||||
class ValueReaders {
|
||||
|
||||
static final ValueReaders VALUE_READERS = new ValueReaders();
|
||||
|
||||
Object convert(String value, AtomicInteger index, dev.plex.toml.Context context) {
|
||||
String substring = value.substring(index.get());
|
||||
for (dev.plex.toml.ValueReader valueParser : READERS) {
|
||||
if (valueParser.canRead(substring)) {
|
||||
return valueParser.read(value, index, context);
|
||||
}
|
||||
}
|
||||
|
||||
dev.plex.toml.Results.Errors errors = new dev.plex.toml.Results.Errors();
|
||||
errors.invalidValue(context.identifier.getName(), substring, context.line.get());
|
||||
return errors;
|
||||
}
|
||||
|
||||
private ValueReaders() {}
|
||||
|
||||
private static final dev.plex.toml.ValueReader[] READERS = {
|
||||
MULTILINE_STRING_VALUE_READER, MULTILINE_LITERAL_STRING_VALUE_READER, LITERAL_STRING_VALUE_READER, STRING_VALUE_READER_WRITER, DATE_VALUE_READER_WRITER, NUMBER_VALUE_READER_WRITER, BOOLEAN_VALUE_READER_WRITER, ARRAY_VALUE_READER, INLINE_TABLE_VALUE_READER
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user