chiark / gitweb /
svg size handling: Break out tokens as mut iterator
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 2 May 2022 10:35:46 +0000 (11:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 2 May 2022 10:35:46 +0000 (11:35 +0100)
We're going to restructure this to be a bit more like the structure in
bundles.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/utils.rs

index 90a0903d441b87013dd6f303fc028ae0a88cc7c0..c0968f588caf2e86985bf81a5bad48658c308252 100644 (file)
@@ -224,11 +224,14 @@ pub enum SVGSizeError {
 
 #[throws(SVGSizeError)]
 pub fn svg_parse_size(xml: &str) -> Option<PosC<f64>> {
+  let mut tokens = xmlparser::Tokenizer::from(xml)
+    .map(|t| t.map_err(|e| SvSE::ParseError(e.to_string())));
+
   use xmlparser::Token as Tk;
   let mut in_svg_element = false;
   let mut wh = [None; 2];
-  for token in xmlparser::Tokenizer::from(xml) {
-    match token.map_err(|e| SvSE::ParseError(e.to_string()))? {
+  for token in &mut tokens {
+    match token? {
       Tk::ElementStart{ local, .. } => {
         in_svg_element = local.eq_ignore_ascii_case("svg");
       },