Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions node-graph/gcore/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,20 @@ async fn switch<T, C: Send + 'n + Clone>(
if_false.eval(ctx).await
}
}

// Get an indexed part of string whitch separated a specified delimeter ("1;2;3" e.t.c.)
#[node_macro::node(category("Text"))]
fn substring_by_index(_: impl Ctx, #[implementations(String)] string: String, delimeter: String, index: u32) -> String {
let idx = index as usize;
let parts: Vec<&str> = string.split(&delimeter).collect();
if idx < parts.len() { parts[idx].to_string() } else { String::new() }
}

// Get amount substrings like ";" in string (useful for check max index in substring_by_index)
#[node_macro::node(category("Text"))]
fn count_substring(_: impl Ctx, #[implementations(String)] string: String, substring: String) -> f64 {
if substring.is_empty() {
return 0.;
}
string.matches(&substring).count() as f64
}