aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/makefile/functions.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index d746d8a..750d56a 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -16,6 +16,10 @@ pub fn expand_call(
to_eval: Option<Rc<RefCell<Vec<String>>>>,
) -> Result<String> {
match name {
+ "strip" => {
+ assert_eq!(args.len(), 1);
+ text::strip(macros, &args[0])
+ }
"filter" => {
assert_eq!(args.len(), 2);
text::filter(macros, &args[0], &args[1])
@@ -95,6 +99,13 @@ pub fn expand_call(
mod text {
use super::*;
+ pub fn strip(macros: &MacroSet, text: &TokenString) -> Result<String> {
+ let text = macros.expand(text)?;
+ // TODO don't allocate this vec
+ let words = text.split_whitespace().collect::<Vec<_>>();
+ Ok(words.join(" "))
+ }
+
pub fn filter(macros: &MacroSet, patterns: &TokenString, text: &TokenString) -> Result<String> {
let patterns = macros.expand(patterns)?;
let patterns = patterns.split_whitespace().collect::<Vec<_>>();