mirror of
https://github.com/plexusorg/toml4j.git
synced 2024-06-01 01:11:36 +00:00
55 lines
1.9 KiB
Java
55 lines
1.9 KiB
Java
package com.moandjiezana.toml;
|
|
|
|
import static com.moandjiezana.toml.ArrayConverter.ARRAY_PARSER;
|
|
import static com.moandjiezana.toml.BooleanConverter.BOOLEAN_PARSER;
|
|
import static com.moandjiezana.toml.DateConverter.DATE_PARSER;
|
|
import static com.moandjiezana.toml.InlineTableConverter.INLINE_TABLE_PARSER;
|
|
import static com.moandjiezana.toml.LiteralStringConverter.LITERAL_STRING_PARSER;
|
|
import static com.moandjiezana.toml.MultilineLiteralStringConverter.MULTILINE_LITERAL_STRING_CONVERTER;
|
|
import static com.moandjiezana.toml.MultilineStringConverter.MULTILINE_STRING_PARSER;
|
|
import static com.moandjiezana.toml.NumberConverter.NUMBER_PARSER;
|
|
import static com.moandjiezana.toml.StringConverter.STRING_PARSER;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
class ValueConverters {
|
|
|
|
static final ValueConverters CONVERTERS = new ValueConverters();
|
|
|
|
static boolean isComment(String line) {
|
|
if (line == null || line.isEmpty()) {
|
|
return true;
|
|
}
|
|
|
|
for (int i = 0; i < line.length(); i++) {
|
|
char c = line.charAt(i);
|
|
if (Character.isWhitespace(c)) {
|
|
continue;
|
|
}
|
|
|
|
return c == '#';
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
Object convert(String value, AtomicInteger index, Context context) {
|
|
String substring = value.substring(index.get());
|
|
for (ValueConverter valueParser : PARSERS) {
|
|
if (valueParser.canConvert(substring)) {
|
|
return valueParser.convert(value, index, context);
|
|
}
|
|
}
|
|
|
|
Results.Errors errors = new Results.Errors();
|
|
errors.invalidValue(context.identifier.getName(), substring, context.line.get());
|
|
return errors;
|
|
}
|
|
|
|
private ValueConverters() {}
|
|
|
|
private static final ValueConverter[] PARSERS = {
|
|
MULTILINE_STRING_PARSER, MULTILINE_LITERAL_STRING_CONVERTER, LITERAL_STRING_PARSER, STRING_PARSER, DATE_PARSER, NUMBER_PARSER, BOOLEAN_PARSER, ARRAY_PARSER, INLINE_TABLE_PARSER
|
|
};
|
|
}
|