@@ -69,6 +69,20 @@ 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.)
73+ #[ node_macro:: node( category( "Text" ) ) ]
74+ fn substring_by_index ( _: impl Ctx , string : String , #[ default( "\\ n" ) ] delimeter : String , index : u32 ) -> String {
75+ 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
84+ }
85+
7286/// Evaluates either the "If True" or "If False" input branch based on whether the input condition is true or false.
7387#[ node_macro:: node( category( "Math: Logic" ) ) ]
7488async fn switch < T , C : Send + ' n + Clone > (
@@ -120,20 +134,3 @@ async fn switch<T, C: Send + 'n + Clone>(
120134 if_false. eval ( ctx) . await
121135 }
122136}
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. ;
137- }
138- string. matches ( & substring) . count ( ) as f64
139- }
0 commit comments