aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/makefile/functions.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs
index 6e04b7a..6dacd10 100644
--- a/src/makefile/functions.rs
+++ b/src/makefile/functions.rs
@@ -20,6 +20,10 @@ pub fn expand_call(
assert_eq!(args.len(), 1);
text::strip(macros, &args[0])
}
+ "findstring" => {
+ assert_eq!(args.len(), 2);
+ text::findstring(macros, &args[0], &args[1])
+ }
"filter" => {
assert_eq!(args.len(), 2);
text::filter(macros, &args[0], &args[1])
@@ -110,6 +114,20 @@ mod text {
Ok(words.join(" "))
}
+ pub fn findstring(
+ macros: &MacroSet,
+ needle: &TokenString,
+ haystack: &TokenString,
+ ) -> Result<String> {
+ let needle = macros.expand(needle)?;
+ let haystack = macros.expand(haystack)?;
+ if haystack.contains(&needle) {
+ Ok(needle)
+ } else {
+ Ok(String::new())
+ }
+ }
+
pub fn filter(macros: &MacroSet, patterns: &TokenString, text: &TokenString) -> Result<String> {
let patterns = macros.expand(patterns)?;
let patterns = patterns.split_whitespace().collect::<Vec<_>>();
@@ -380,6 +398,13 @@ mod test {
}
#[test]
+ fn findstring() -> R {
+ assert_eq!(call!(findstring "hi", "thighs"), "hi");
+ assert_eq!(call!(findstring "hey", "hello there"), "");
+ Ok(())
+ }
+
+ #[test]
fn filter() -> R {
let result = call!(filter "word", "this contains a word inside it");
assert_eq!(result, "word");