[librsvg/rustification] path_parser.rs: Test and fix handling of numbers with decimals
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustification] path_parser.rs: Test and fix handling of numbers with decimals
- Date: Fri, 4 Nov 2016 20:39:46 +0000 (UTC)
commit 5d07d93a20eaf900417959f1d756373b01bc9248
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Nov 4 13:59:23 2016 -0600
path_parser.rs: Test and fix handling of numbers with decimals
rust/src/path_parser.rs | 35 ++++++++++++++++++++++++-----------
1 files changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index fb2155b..226b32c 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -110,6 +110,16 @@ impl<'external> PathParser<'external> {
}
}
+ fn lookahead_is (&self, c: char) -> bool {
+ if let Some (x) = self.lookahead {
+ if x == c {
+ return true;
+ }
+ }
+
+ false
+ }
+
fn lookahead_is_digit (&self, d: &mut char) -> bool {
if let Some (c) = self.lookahead {
if c.is_digit (10) {
@@ -144,7 +154,7 @@ impl<'external> PathParser<'external> {
let mut c: char = ' ';
- if self.lookahead_is_digit (&mut c) {
+ if self.lookahead_is_digit (&mut c) || self.lookahead_is ('.') {
/* Integer part */
while self.lookahead_is_digit (&mut c) {
@@ -218,16 +228,6 @@ impl<'external> PathParser<'external> {
None
}
- fn lookahead_is (&self, c: char) -> bool {
- if let Some (x) = self.lookahead {
- if x == c {
- return true;
- }
- }
-
- false
- }
-
fn emit_line_to (&mut self, absolute: bool, x: f64, y: f64) {
if absolute {
self.current_x = x;
@@ -481,6 +481,19 @@ mod tests {
}
#[test]
+ fn path_parser_handles_numbers () {
+ test_parser ("M 10 20",
+ &vec![
+ moveto (10.0, 20.0)
+ ]);
+
+ test_parser ("M .10 0.20",
+ &vec![
+ moveto (0.10, 0.20)
+ ]);
+ }
+
+ #[test]
fn path_parser_handles_single_moveto () {
test_parser ("M 10 20",
&vec![
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]