| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
use core::{fmt, str::FromStr}; |
| 6 |
|
| 7 |
use crate::{ParsedPatternItem, Parser, PatternError, PatternItemCow}; |
| 8 |
|
| 9 |
impl<'a, K> From<ParsedPatternItem<'a, K>> for PatternItemCow<'a, K> { |
| 10 |
fn from(value: ParsedPatternItem<'a, K>) -> Self { |
| 11 |
match value { |
| 12 |
ParsedPatternItem::Literal { content, .. } => PatternItemCow::Literal(content), |
| 13 |
ParsedPatternItem::Placeholder(key) => PatternItemCow::Placeholder(key), |
| 14 |
} |
| 15 |
} |
| 16 |
} |
| 17 |
|
| 18 |
impl<'a, K> Iterator for Parser<'a, K> |
| 19 |
where |
| 20 |
K: FromStr, |
| 21 |
K::Err: fmt::Debug, |
| 22 |
{ |
| 23 |
type Item = Result<PatternItemCow<'a, K>, PatternError>; |
| 24 |
|
| 25 |
fn next(&mut self) -> Option<Self::Item> { |
| 26 |
match self.try_next() { |
| 27 |
Ok(Some(pattern_token)) => Some(Ok(pattern_token.into())), |
| 28 |
Ok(None) => None, |
| 29 |
Err(_e) => Some(Err(PatternError::InvalidPattern)), |
| 30 |
} |
| 31 |
} |
| 32 |
} |