From e3c7df868b638f8dbf2423401b2fb72fc0779249 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sun, 4 Apr 2021 14:57:44 -0600 Subject: implement `strip` function --- src/makefile/functions.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) 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>>>, ) -> Result { 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 { + let text = macros.expand(text)?; + // TODO don't allocate this vec + let words = text.split_whitespace().collect::>(); + Ok(words.join(" ")) + } + pub fn filter(macros: &MacroSet, patterns: &TokenString, text: &TokenString) -> Result { let patterns = macros.expand(patterns)?; let patterns = patterns.split_whitespace().collect::>(); -- cgit v1.2.3