Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fea-rs/src/compile/compile_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ impl<'a, F: FeatureProvider, V: VariationInfo> CompilationCtx<'a, F, V> {
platform_id,
encoding_id,
language_id,
string: node.string().into(),
string: SmolStr::from(node.string().as_ref()),
}
}

Expand Down
9 changes: 4 additions & 5 deletions fea-rs/src/parse/grammar/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,11 @@ mod tests {

crate::typed::NameSpec::cast(&token).unwrap()
};
assert_eq!("", parse_name("3 1 0x409 \"\"").string());
assert_eq!("duck", parse_name("3 1 0x409 \"duck\"").string());
assert_eq!(
["", "duck"],
[
parse_name("3 1 0x409 \"\"").string(),
parse_name("3 1 0x409 \"duck\"").string(),
]
"i have some newlines",
parse_name("3 1 0x409 \"i have\n some \rnewlines\"").string()
);
}
}
12 changes: 10 additions & 2 deletions fea-rs/src/token_tree/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//! This lets us implement useful methods on specific AST nodes, which are
//! internally working on untyped `NodeOrToken`s.

use std::borrow::Cow;
use std::convert::TryFrom;
use std::ops::Range;

Expand Down Expand Up @@ -1549,10 +1550,17 @@ impl NameSpec {
self.find_token(Kind::String).unwrap()
}

pub(crate) fn string(&self) -> &str {
pub(crate) fn string(&self) -> Cow<'_, str> {
// The value is always doublequoted so slice out the actual string
let s = self.string_token().as_str();
&s[1..s.len() - 1]
let s = &s[1..s.len() - 1];
// Per the FEA spec: "Newlines embedded within the string are removed
// from the character sequence to be stored."
if s.contains(['\n', '\r']) {
Cow::Owned(s.replace(['\n', '\r'], ""))
} else {
Cow::Borrowed(s)
}
}
}

Expand Down
Loading