[librsvg: 3/23] Convert the locale to LanguageTags only once




commit 93a490931d096b4164e893e416ab823215b270bf
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue May 18 17:18:33 2021 -0500

    Convert the locale to LanguageTags only once

 src/cond.rs | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
---
diff --git a/src/cond.rs b/src/cond.rs
index 9132d0f9..661d3077 100644
--- a/src/cond.rs
+++ b/src/cond.rs
@@ -139,6 +139,9 @@ impl SystemLanguage {
     /// [`systemLanguage`]: 
https://www.w3.org/TR/SVG/struct.html#ConditionalProcessingSystemLanguageAttribute
     /// [BCP47]: http://www.ietf.org/rfc/bcp/bcp47.txt
     pub fn from_attribute(s: &str, locale: &Locale) -> Result<SystemLanguage, ValueErrorKind> {
+        let locale_tags =
+            LanguageTags::from_locale(locale).map_err(|e| ValueErrorKind::value_error(&e))?;
+
         s.split(',')
             .map(str::trim)
             .map(LanguageTag::from_str)
@@ -152,7 +155,7 @@ impl SystemLanguage {
                         if have_match {
                             Ok(SystemLanguage(have_match))
                         } else {
-                            locale_accepts_language_tag(locale, &language_tag).map(SystemLanguage)
+                            Ok(SystemLanguage(locale_tags.any_matches(&language_tag)))
                         }
                     }
 
@@ -170,15 +173,6 @@ impl SystemLanguage {
     }
 }
 
-fn locale_accepts_language_tag(
-    locale: &Locale,
-    language_tag: &LanguageTag,
-) -> Result<bool, ValueErrorKind> {
-    let tags = LanguageTags::from_locale(locale).map_err(|e| ValueErrorKind::value_error(&e))?;
-
-    Ok(tags.any_matches(language_tag))
-}
-
 #[cfg(test)]
 mod tests {
     use super::*;


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