mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-02-11 03:30:00 +00:00
Literal strings no longer handled by Parboiled
This commit is contained in:
parent
bde639951a
commit
40cab5c499
2 changed files with 28 additions and 11 deletions
|
@ -1,9 +1,7 @@
|
|||
package com.moandjiezana.toml;
|
||||
|
||||
import static com.moandjiezana.toml.ValueConverterUtils.parse;
|
||||
import static com.moandjiezana.toml.ValueConverterUtils.parser;
|
||||
import static com.moandjiezana.toml.ValueConverterUtils.INVALID;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class LiteralStringConverter implements ValueConverter {
|
||||
|
||||
|
@ -16,13 +14,36 @@ class LiteralStringConverter implements ValueConverter {
|
|||
|
||||
@Override
|
||||
public Object convert(String s) {
|
||||
List<String> resultValue = parse(parser().LiteralString(), s);
|
||||
char[] chars = s.toCharArray();
|
||||
boolean terminated = false;
|
||||
StringBuilder sb = new StringBuilder(s.length());
|
||||
|
||||
if (resultValue == null) {
|
||||
return ValueConverterUtils.INVALID;
|
||||
for (int i = 1; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
|
||||
if (c == '\'') {
|
||||
terminated = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!terminated) {
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
if (terminated && c == '#') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (terminated && !Character.isWhitespace(c)) {
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
return resultValue.get(0);
|
||||
if (!terminated) {
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private LiteralStringConverter() {}
|
||||
|
|
|
@ -14,10 +14,6 @@ class ValueParser extends BaseParser<List<Object>> {
|
|||
return FirstOf(EmptyArray(), Sequence('[', startList(), OneOrMore(FirstOf(NonEmptyArray(), ' ', ',')), ']', endList()));
|
||||
}
|
||||
|
||||
public Rule LiteralString() {
|
||||
return FirstOf(EmptyLiteralString(), Sequence('\'', OneOrMore(TestNot("'"), ANY), startList(), pushToken(match()) , '\'', endList(), Comment()));
|
||||
}
|
||||
|
||||
public Rule MultilineLiteralString() {
|
||||
return FirstOf(EmptyMultilineLiteralString(), Sequence("'''", startList(), Sequence(OneOrMore(TestNot("'''"), ANY), pushToken(match())), "'''", endList(), Comment()));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue