Support integer with leading plus sign

This commit is contained in:
moandji.ezana 2014-11-10 22:01:46 +02:00
parent 53aba456ce
commit 16e9fa16f0
3 changed files with 14 additions and 2 deletions

View file

@ -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() {}

View file

@ -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() {

View file

@ -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 {