[librsvg: 4/23] Convert the systemLanguage attribute to LanguageTags, then look for matches




commit 0e7b35f7288c8a07d82a2a16f67d08ed9ecb2ca3
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue May 18 17:30:49 2021 -0500

    Convert the systemLanguage attribute to LanguageTags, then look for matches

 src/cond.rs | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)
---
diff --git a/src/cond.rs b/src/cond.rs
index 661d3077..d7c9b88d 100644
--- a/src/cond.rs
+++ b/src/cond.rs
@@ -142,29 +142,16 @@ impl SystemLanguage {
         let locale_tags =
             LanguageTags::from_locale(locale).map_err(|e| ValueErrorKind::value_error(&e))?;
 
-        s.split(',')
+        let attribute_tags = s.split(',')
             .map(str::trim)
-            .map(LanguageTag::from_str)
-            .try_fold(
-                // start with no match
-                SystemLanguage(false),
-                // The accumulator is Result<SystemLanguage, ValueErrorKind>
-                |acc, tag_result| match tag_result {
-                    Ok(language_tag) => {
-                        let have_match = acc.0;
-                        if have_match {
-                            Ok(SystemLanguage(have_match))
-                        } else {
-                            Ok(SystemLanguage(locale_tags.any_matches(&language_tag)))
-                        }
-                    }
-
-                    Err(e) => Err(ValueErrorKind::parse_error(&format!(
-                        "invalid language tag: \"{}\"",
-                        e
-                    ))),
-                },
-            )
+            .map(|s| LanguageTag::from_str(s).map_err(|e| ValueErrorKind::parse_error(&format!(
+                "invalid language tag: \"{}\"",
+                e
+            ))))
+            .collect::<Result<Vec<LanguageTag>, _>>()?;
+
+        let matches = attribute_tags.iter().any(|tag| locale_tags.any_matches(tag));
+        Ok(SystemLanguage(matches))
     }
 
     /// Evaluate a systemLanguage value for conditional processing.


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