summaryrefslogtreecommitdiff
path: root/src/macro_processor
diff options
context:
space:
mode:
authorQrius <[email protected]>2024-11-12 14:49:14 +0100
committerQrius <[email protected]>2024-11-12 14:49:14 +0100
commit1a27e733f961893b5cb1a92b1b9927e31631c936 (patch)
treed016cbd1e6a6577642aafcfc13328cd621f8c28b /src/macro_processor
parent482290c40763796f530ebe0812bacf905af194fc (diff)
downloadskaldpress-1a27e733f961893b5cb1a92b1b9927e31631c936.tar.gz
skaldpress-1a27e733f961893b5cb1a92b1b9927e31631c936.zip
Add explode function, add auto filename metadata
Diffstat (limited to 'src/macro_processor')
-rw-r--r--src/macro_processor/macro_processor.rs39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs
index a9585bb..0b714f0 100644
--- a/src/macro_processor/macro_processor.rs
+++ b/src/macro_processor/macro_processor.rs
@@ -397,7 +397,10 @@ fn smp_builtin_array_each(
let mut out = String::new();
for el in array.clone() {
let exp = match el {
- MacroType::String(s) => smp.expand_macro(&args[1], &mut [s])?,
+ MacroType::String(s) => {
+ let n = smp.expand_macro(&args[1], &mut [s])?;
+ smp.process_input(&n)?
+ }
MacroType::Array(a) => {
let mut out = Vec::new();
for _el in a {
@@ -440,6 +443,36 @@ fn smp_builtin_array_size(
Ok(array.len().to_string())
}
+/// Split input into array
+fn smp_builtin_explode(
+ smp: &mut MacroProcessor,
+ macro_name: &str,
+ args: &mut [String],
+) -> Result<String, SMPError> {
+ if args.len() != 3 {
+ smp.warnings
+ .push(MacroProcessorWarning::from_macro_invocation(
+ macro_name,
+ args,
+ format!("Wrong number of arguments, expected 3"),
+ ));
+ return Ok(macro_name.to_string());
+ }
+ let split = smp.process_input(&args[1])?;
+ for c in smp.process_input(&args[2])?.split(&split) {
+ if let Err(e) = smp.array_push(&args[0], MacroType::String(String::from(c))) {
+ smp.warnings
+ .push(MacroProcessorWarning::from_macro_invocation(
+ macro_name,
+ args,
+ format!("Error executing array_push ({:?})", e),
+ ));
+ }
+ }
+
+ Ok(String::new())
+}
+
#[cfg(feature = "time")]
fn smp_builtin_format_time(
smp: &mut MacroProcessor,
@@ -664,6 +697,10 @@ impl MacroProcessor {
String::from("array_size"),
MacroType::Function(smp_builtin_array_size),
);
+ self.define_macro(
+ String::from("explode"),
+ MacroType::Function(smp_builtin_explode),
+ );
#[cfg(feature = "time")]
self.define_macro(
String::from("format_time"),