mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-02-11 11:40:27 +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;
|
package com.moandjiezana.toml;
|
||||||
|
|
||||||
import static com.moandjiezana.toml.ValueConverterUtils.parse;
|
import static com.moandjiezana.toml.ValueConverterUtils.INVALID;
|
||||||
import static com.moandjiezana.toml.ValueConverterUtils.parser;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
class LiteralStringConverter implements ValueConverter {
|
class LiteralStringConverter implements ValueConverter {
|
||||||
|
|
||||||
|
@ -16,13 +14,36 @@ class LiteralStringConverter implements ValueConverter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object convert(String s) {
|
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) {
|
for (int i = 1; i < chars.length; i++) {
|
||||||
return ValueConverterUtils.INVALID;
|
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() {}
|
private LiteralStringConverter() {}
|
||||||
|
|
|
@ -14,10 +14,6 @@ class ValueParser extends BaseParser<List<Object>> {
|
||||||
return FirstOf(EmptyArray(), Sequence('[', startList(), OneOrMore(FirstOf(NonEmptyArray(), ' ', ',')), ']', endList()));
|
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() {
|
public Rule MultilineLiteralString() {
|
||||||
return FirstOf(EmptyMultilineLiteralString(), Sequence("'''", startList(), Sequence(OneOrMore(TestNot("'''"), ANY), pushToken(match())), "'''", endList(), Comment()));
|
return FirstOf(EmptyMultilineLiteralString(), Sequence("'''", startList(), Sequence(OneOrMore(TestNot("'''"), ANY), pushToken(match())), "'''", endList(), Comment()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue