From 9dd46d6fbfac371f4489f6fbcce7301a9abfeb36 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 15 Jan 2015 14:27:55 -0800 Subject: Fix parsing leading `+` on numbers --- src/parser.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/parser.rs b/src/parser.rs index 721c83c..93aa830 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -254,7 +254,8 @@ impl<'a> Parser<'a> { Some((pos, 't')) | Some((pos, 'f')) => self.boolean(pos), Some((pos, '[')) => self.array(pos), - Some((pos, '-')) => self.number_or_datetime(pos), + Some((pos, '-')) | + Some((pos, '+')) => self.number_or_datetime(pos), Some((pos, ch)) if ch.is_digit(10) => self.number_or_datetime(pos), _ => { let mut it = self.cur.clone(); @@ -453,8 +454,8 @@ impl<'a> Parser<'a> { return Some(Value::String(ret)); } - fn number_or_datetime(&mut self, start: usize) -> Option { - let negative = self.eat('-'); + fn number_or_datetime(&mut self, mut start: usize) -> Option { + let sign = if self.eat('+') { start += 1; true } else {self.eat('-')}; let mut is_float = false; loop { match self.cur.clone().next() { @@ -473,7 +474,7 @@ impl<'a> Parser<'a> { } else { self.input.slice(start, end).parse().map(Float) } - } else if !negative && self.eat('-') { + } else if !sign && self.eat('-') { self.datetime(start, end + 1) } else { self.input.slice(start, end).parse().map(Integer) -- cgit v1.2.3