diff --git a/node-graph/gcore/src/logic.rs b/node-graph/gcore/src/logic.rs index 84842e0000..0b978c92fb 100644 --- a/node-graph/gcore/src/logic.rs +++ b/node-graph/gcore/src/logic.rs @@ -69,6 +69,20 @@ fn string_length(_: impl Ctx, string: String) -> f64 { string.chars().count() as f64 } +// 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, string: String, #[default("\\n")] delimeter: String, index: u32) -> String { + let delimeter = delimeter.replace("\\n", "\n"); + string.split(&delimeter).nth(index as usize).unwrap_or("").to_owned() +} + +// 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, string: String, #[default("\\n")] substring: String) -> f64 { + let substring = substring.replace("\\n", "\n"); + string.matches(&substring).count() as f64 +} + /// Evaluates either the "If True" or "If False" input branch based on whether the input condition is true or false. #[node_macro::node(category("Math: Logic"))] async fn switch( diff --git a/node-graph/node-macro/src/codegen.rs b/node-graph/node-macro/src/codegen.rs index 09d2e4af4f..a749174ab8 100644 --- a/node-graph/node-macro/src/codegen.rs +++ b/node-graph/node-macro/src/codegen.rs @@ -88,7 +88,15 @@ pub(crate) fn generate_node_code(crate_ident: &CrateIdent, parsed: &ParsedNodeFn .iter() .map(|field| match &field.ty { ParsedFieldType::Regular(RegularParsedField { value_source, .. }) => match value_source { - ParsedValueSource::Default(data) => quote!(RegistryValueSource::Default(stringify!(#data))), + ParsedValueSource::Default(data) => { + // Check if the data is a string literal by parsing the token stream + let data_str = data.to_string(); + if data_str.starts_with('"') && data_str.ends_with('"') && data_str.len() >= 2 { + quote!(RegistryValueSource::Default(#data)) + } else { + quote!(RegistryValueSource::Default(stringify!(#data))) + } + } ParsedValueSource::Scope(data) => quote!(RegistryValueSource::Scope(#data)), _ => quote!(RegistryValueSource::None), },