From 88c059301e291792a23413fe54580ff137608d7b Mon Sep 17 00:00:00 2001 From: rsheeter Date: Fri, 6 Dec 2024 14:13:45 -0800 Subject: [PATCH] Avoid adding blank names --- fea-rs/src/compile/tables/name.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/fea-rs/src/compile/tables/name.rs b/fea-rs/src/compile/tables/name.rs index cb4f042d..d5a248f3 100644 --- a/fea-rs/src/compile/tables/name.rs +++ b/fea-rs/src/compile/tables/name.rs @@ -14,7 +14,7 @@ pub(crate) struct NameBuilder { last_nonreserved_id: NameId, } -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, PartialEq)] pub(crate) struct NameSpec { pub platform_id: u16, pub encoding_id: u16, @@ -22,6 +22,12 @@ pub(crate) struct NameSpec { pub string: SmolStr, } +impl NameSpec { + fn is_empty(&self) -> bool { + self.string.is_empty() + } +} + impl Default for NameBuilder { fn default() -> Self { NameBuilder { @@ -40,8 +46,8 @@ impl NameBuilder { pub(crate) fn add_anon_group(&mut self, entries: &[NameSpec]) -> NameId { let name_id = self.next_name_id(); - for name in entries { - self.add(name_id, name.clone()); + for name_spec in entries.iter().filter(|n| !n.is_empty()) { + self.add(name_id, name_spec.clone()); } name_id } @@ -195,4 +201,23 @@ mod tests { let inp = "M\\9fller"; assert_eq!(parse_mac(inp), "Müller"); } + + #[test] + fn ignore_empty_names() { + let blank = NameSpec { + platform_id: 3, + encoding_id: 1, + language_id: 0x409, + string: "".into(), + }; + let mallard = NameSpec { + platform_id: 3, + encoding_id: 1, + language_id: 0x409, + string: "mallard".into(), + }; + let mut nb = NameBuilder::default(); + nb.add_anon_group(&[blank, mallard.clone()]); + assert_eq!(vec![(NameId::new(256), mallard)], nb.records); + } }