Skip to content

Commit ac1dce3

Browse files
daniil.lobanTrueDoctor
authored andcommitted
Add two nodes for substring
1 parent c4bbb7e commit ac1dce3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

node-graph/gcore/src/logic.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,20 @@ async fn switch<T, C: Send + 'n + Clone>(
120120
if_false.eval(ctx).await
121121
}
122122
}
123+
124+
// Get an indexed part of string whitch separated a specified delimeter ("1;2;3" e.t.c.)
125+
#[node_macro::node(category("Text"))]
126+
fn substring_by_index(_: impl Ctx, #[implementations(String)] string: String, delimeter: String, index: u32) -> String {
127+
let idx = index as usize;
128+
let parts: Vec<&str> = string.split(&delimeter).collect();
129+
if idx < parts.len() { parts[idx].to_string() } else { String::new() }
130+
}
131+
132+
// Get amount substrings like ";" in string (useful for check max index in substring_by_index)
133+
#[node_macro::node(category("Text"))]
134+
fn count_substring(_: impl Ctx, #[implementations(String)] string: String, substring: String) -> f64 {
135+
if substring.is_empty() {
136+
return 0.0;
137+
}
138+
string.matches(&substring).count() as f64
139+
}

0 commit comments

Comments
 (0)