aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-06 20:00:56 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-06 20:00:56 -0600
commit49d15d615129fc04bb493b27228b554837b20f99 (patch)
tree27425b574b4befb8868419b52e6197f32fa26cde /src
parentb194c5e5f4a858b39bd7b3563446fa87cfb3ce98 (diff)
downloadmakers-49d15d615129fc04bb493b27228b554837b20f99.tar.gz
makers-49d15d615129fc04bb493b27228b554837b20f99.zip
implement function `firstword`
Diffstat (limited to 'src')
-rw-r--r--src/makefile/functions.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index 51bf0f9..feb0e54 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -52,6 +52,10 @@ pub fn expand_call(
assert_eq!(args.len(), 1);
text::words(macros, &args[0])
}
+ "firstword" => {
+ assert_eq!(args.len(), 1);
+ text::firstword(macros, &args[0])
+ }
"lastword" => {
assert_eq!(args.len(), 1);
text::lastword(macros, &args[0])
@@ -266,6 +270,11 @@ mod text {
Ok(words.split_whitespace().count().to_string())
}
+ pub fn firstword(macros: &MacroSet, words: &TokenString) -> Result<String> {
+ let words = macros.expand(words)?;
+ Ok(words.split_whitespace().nth(0).unwrap_or("").to_owned())
+ }
+
pub fn lastword(macros: &MacroSet, words: &TokenString) -> Result<String> {
let words = macros.expand(words)?;
Ok(words.split_whitespace().last().unwrap_or("").to_owned())