diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-05 11:55:32 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-05 11:55:32 -0600 |
commit | f7b8de180cc8db854ceba3f1644e9d7387d74ae3 (patch) | |
tree | 200c909f68c6072e2d26212d31b871fee98319f0 | |
parent | e21f0b7804848d8a0600b97f9cf0b5c01059e7ce (diff) | |
download | makers-f7b8de180cc8db854ceba3f1644e9d7387d74ae3.tar.gz makers-f7b8de180cc8db854ceba3f1644e9d7387d74ae3.zip |
implement function `words`
-rw-r--r-- | src/makefile/functions.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs index f1d43de..6e9d3cb 100644 --- a/src/makefile/functions.rs +++ b/src/makefile/functions.rs @@ -36,6 +36,10 @@ pub fn expand_call( assert_eq!(args.len(), 1); text::sort(macros, &args[0]) } + "words" => { + assert_eq!(args.len(), 1); + text::words(macros, &args[0]) + } "lastword" => { assert_eq!(args.len(), 1); text::lastword(macros, &args[0]) @@ -186,6 +190,11 @@ mod text { Ok(words.join(" ")) } + pub fn words(macros: &MacroSet, words: &TokenString) -> Result<String> { + let words = macros.expand(words)?; + Ok(words.split_whitespace().count().to_string()) + } + pub fn lastword(macros: &MacroSet, words: &TokenString) -> Result<String> { let words = macros.expand(words)?; Ok(words.split_whitespace().last().unwrap_or("").to_owned()) |