[librsvg: 9/28] path_parser: moveto(): Distinguish between EOF and an unexpected token



commit 4199af6529c0aef386fade35de2462a90c1b0407
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Jan 23 09:48:03 2018 -0600

    path_parser: moveto(): Distinguish between EOF and an unexpected token
    
    The M/m commands are special, because the beginning of the path
    string *must* have one of them.  So, our moveto() has a different
    signature from e.g. line_to():
    
    - moveto() -> Result<(), ParseError> - means "parsed a Moveto or error"
    
    - line_to() -> Result<bool, ParseError> - means "found/didn't find a Lineto, or error"
    
    The functions which can look for optional commands (line_to(),
    curve_to(), etc.) return a bool in the Ok() case, to indicate whether
    they actually found their respective command.  Since the moveto() is
    not optional, it returns Ok(()), not Ok(bool).

 rust/src/path_parser.rs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
---
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index 9fb9db8..d2fc1a7 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -430,8 +430,10 @@ impl<'b> PathParser<'b> {
 
             self.optional_whitespace()?;
             self.moveto_argument_sequence(absolute, is_initial_moveto)
-        } else {
+        } else if self.lookahead.is_some() {
             Err(self.error(ErrorKind::UnexpectedToken))
+        } else {
+            Err(self.error(ErrorKind::UnexpectedEof))
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]