From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/fluent-bundle/src/args.rs | 74 ++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 third_party/rust/fluent-bundle/src/args.rs (limited to 'third_party/rust/fluent-bundle/src/args.rs') diff --git a/third_party/rust/fluent-bundle/src/args.rs b/third_party/rust/fluent-bundle/src/args.rs new file mode 100644 index 0000000000..368d70e4ed --- /dev/null +++ b/third_party/rust/fluent-bundle/src/args.rs @@ -0,0 +1,74 @@ +use std::borrow::Cow; +use std::iter::FromIterator; + +use crate::types::FluentValue; + +/// A map of arguments passed from the code to +/// the localization to be used for message +/// formatting. +#[derive(Debug, Default)] +pub struct FluentArgs<'args>(Vec<(Cow<'args, str>, FluentValue<'args>)>); + +impl<'args> FluentArgs<'args> { + pub fn new() -> Self { + Self(vec![]) + } + + pub fn with_capacity(capacity: usize) -> Self { + Self(Vec::with_capacity(capacity)) + } + + pub fn get(&self, key: &str) -> Option<&FluentValue<'args>> { + self.0.iter().find(|(k, _)| key == *k).map(|(_, v)| v) + } + + pub fn add(&mut self, key: K, value: FluentValue<'args>) + where + K: Into>, + { + self.0.push((key.into(), value)); + } + + pub fn iter(&self) -> impl Iterator { + self.0.iter().map(|(k, v)| (k.as_ref(), v)) + } +} + +impl<'args> FromIterator<(&'args str, FluentValue<'args>)> for FluentArgs<'args> { + fn from_iter(iter: I) -> Self + where + I: IntoIterator)>, + { + let mut c = FluentArgs::new(); + + for (k, v) in iter { + c.add(k, v); + } + + c + } +} + +impl<'args> FromIterator<(String, FluentValue<'args>)> for FluentArgs<'args> { + fn from_iter(iter: I) -> Self + where + I: IntoIterator)>, + { + let mut c = FluentArgs::new(); + + for (k, v) in iter { + c.add(k, v); + } + + c + } +} + +impl<'args> IntoIterator for FluentArgs<'args> { + type Item = (Cow<'args, str>, FluentValue<'args>); + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} -- cgit v1.2.3