diff options
author | Melody Horn <melody@boringcactus.com> | 2021-04-05 11:51:52 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-04-05 11:51:52 -0600 |
commit | e8863d5454cf1b2844a55636e1b7a00e0977d998 (patch) | |
tree | 2f76f2305226ba01d0a1f95828207ac97c9a7c69 /src/makefile | |
parent | c7b5ea27156b68971d1fc46935e9e5b63243b9ba (diff) | |
download | makers-e8863d5454cf1b2844a55636e1b7a00e0977d998.tar.gz makers-e8863d5454cf1b2844a55636e1b7a00e0977d998.zip |
implement function `lastword`
Diffstat (limited to 'src/makefile')
-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 4ead48f..f1d43de 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]) } + "lastword" => { + assert_eq!(args.len(), 1); + text::lastword(macros, &args[0]) + } "dir" => { assert_eq!(args.len(), 1); @@ -181,6 +185,11 @@ mod text { words.dedup(); Ok(words.join(" ")) } + + pub fn lastword(macros: &MacroSet, words: &TokenString) -> Result<String> { + let words = macros.expand(words)?; + Ok(words.split_whitespace().last().unwrap_or("").to_owned()) + } } // File Name Functions |