Skip to content

Commit c6ef366

Browse files
committed
Make split node return Vec<String> and remove count_elements node
1 parent 6fc9f0f commit c6ef366

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

node-graph/gcore/src/graphic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ fn index<T: AtIndex + Clone + Default>(
451451
Vec<u32>,
452452
Vec<u64>,
453453
Vec<DVec2>,
454+
Vec<String>,
454455
Table<Artboard>,
455456
Table<Graphic>,
456457
Table<Vector>,

node-graph/gcore/src/logic.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,11 @@ fn string_length(_: impl Ctx, string: String) -> f64 {
6969
string.chars().count() as f64
7070
}
7171

72-
// Get an indexed part of string whitch separated a specified delimeter ("1;2;3" e.t.c.)
72+
// Spliet a string by a specified delimeter ("1;2;3" e.t.c.) and return a vector of strings
7373
#[node_macro::node(category("Text"))]
74-
fn substring_by_index(_: impl Ctx, string: String, #[default("\\n")] delimeter: String, index: u32) -> String {
74+
fn split(_: impl Ctx, string: String, #[default("\\n")] delimeter: String) -> Vec<String> {
7575
let delimeter = delimeter.replace("\\n", "\n");
76-
string.split(&delimeter).nth(index as usize).unwrap_or("").to_owned()
77-
}
78-
79-
// Get amount substrings like ";" in string (useful for check max index in substring_by_index)
80-
#[node_macro::node(category("Text"))]
81-
fn count_substring(_: impl Ctx, string: String, #[default("\\n")] substring: String) -> f64 {
82-
let substring = substring.replace("\\n", "\n");
83-
string.matches(&substring).count() as f64
76+
string.split(&delimeter).map(|x| x.to_string()).collect()
8477
}
8578

8679
/// Evaluates either the "If True" or "If False" input branch based on whether the input condition is true or false.

node-graph/gcore/src/vector/vector_nodes.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,11 +1954,28 @@ fn point_inside(_: impl Ctx, source: Table<Vector>, point: DVec2) -> bool {
19541954
source.into_iter().any(|row| row.element.check_point_inside_shape(row.transform, point))
19551955
}
19561956

1957+
trait Count {
1958+
fn count(&self) -> usize;
1959+
}
1960+
impl<T> Count for Table<T> {
1961+
fn count(&self) -> usize {
1962+
self.len()
1963+
}
1964+
}
1965+
impl<T> Count for Vec<T> {
1966+
fn count(&self) -> usize {
1967+
self.len()
1968+
}
1969+
}
1970+
19571971
// TODO: Return u32, u64, or usize instead of f64 after #1621 is resolved and has allowed us to implement automatic type conversion in the node graph for nodes with generic type inputs.
19581972
// TODO: (Currently automatic type conversion only works for concrete types, via the Graphene preprocessor and not the full Graphene type system.)
19591973
#[node_macro::node(category("General"), path(graphene_core::vector))]
1960-
async fn count_elements<I>(_: impl Ctx, #[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>)] source: Table<I>) -> f64 {
1961-
source.len() as f64
1974+
async fn count_elements<I: Count>(
1975+
_: impl Ctx,
1976+
#[implementations(Table<Graphic>, Table<Vector>, Table<Raster<CPU>>, Table<Raster<GPU>>, Table<Color>, Table<GradientStops>, Vec<String>, Vec<f64>, Vec<DVec2>)] source: I,
1977+
) -> f64 {
1978+
source.count() as f64
19621979
}
19631980

19641981
#[node_macro::node(category("Vector: Measure"), path(graphene_core::vector))]

0 commit comments

Comments
 (0)