mirror of
https://github.com/plexusorg/toml4j.git
synced 2024-12-29 11:42:15 +00:00
Support integer with leading plus sign
This commit is contained in:
parent
53aba456ce
commit
16e9fa16f0
3 changed files with 14 additions and 2 deletions
|
@ -17,7 +17,12 @@ class IntegerConverter implements ValueConverter {
|
|||
public Object convert(String s) {
|
||||
List<String> resultValue = parse(parser().Integer(), s);
|
||||
|
||||
return Long.valueOf(resultValue.get(0));
|
||||
String longString = resultValue.get(0);
|
||||
if (longString.startsWith("+")) {
|
||||
longString = longString.substring(1);
|
||||
}
|
||||
|
||||
return Long.valueOf(longString);
|
||||
}
|
||||
|
||||
private IntegerConverter() {}
|
||||
|
|
|
@ -48,7 +48,7 @@ class ValueParser extends BaseParser<List<Object>> {
|
|||
}
|
||||
|
||||
public Rule Integer() {
|
||||
return Sequence(startList(), Sequence(Sequence(Optional('-'), OneOrMore(CharRange('0', '9'))), pushToken(match())), endList(), Comment());
|
||||
return Sequence(startList(), Sequence(Sequence(Optional(AnyOf("+-")), OneOrMore(CharRange('0', '9'))), pushToken(match())), endList(), Comment());
|
||||
}
|
||||
|
||||
Rule NonEmptyArray() {
|
||||
|
|
|
@ -87,6 +87,13 @@ public class TomlTest {
|
|||
|
||||
assertEquals(-1001, toml.getLong("b").intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_get_number_with_plus_sign() throws Exception {
|
||||
Toml toml = new Toml().parse("a = +1001\nb = 1001");
|
||||
|
||||
assertEquals(toml.getLong("b"), toml.getLong("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_get_array() throws Exception {
|
||||
|
|
Loading…
Reference in a new issue