Skip to content

Commit

Permalink
Fix baked_exporter.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Aug 17, 2023
1 parent 241b563 commit cd0d86c
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion provider/datagen/src/baked_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,46 @@ impl BakedExporter {
let mut map = BTreeMap::new();
let mut statics = Vec::new();

#[derive(Copy, Clone)]
enum ZeroOneOrTwo<T> {
Zero,
One(T),
Two(T, T)
}
impl<T: Copy> Iterator for ZeroOneOrTwo<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
match *self {
ZeroOneOrTwo::Zero => None,
ZeroOneOrTwo::One(a) => {
*self = ZeroOneOrTwo::Zero;
Some(a)
}
ZeroOneOrTwo::Two(a, b) => {
*self = ZeroOneOrTwo::One(b);
Some(a)
}
}
}
}

for (bake, locales) in values {
let first_locale = locales.iter().next().unwrap();
let anchor = syn::parse_str::<syn::Ident>(
&first_locale.to_ascii_uppercase().replace('-', "_").replace(AuxiliaryKey::separator(), "__"),
&first_locale
.chars()
.map(|b| b.to_ascii_uppercase())
.flat_map(|ch| {
if ch == AuxiliaryKey::separator() as char {
// Replace the aux key separator with double-underscore
ZeroOneOrTwo::Two('_', '_')
} else if ch == '-' {
ZeroOneOrTwo::One('_')
} else {
ZeroOneOrTwo::One(ch)
}
})
.collect::<String>(),
)
.unwrap();
let bake = bake.parse::<TokenStream>().unwrap();
Expand Down

0 comments on commit cd0d86c

Please sign in to comment.