Blender V5.3
node_fn_split_string.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_string_utf8.hh"
6
7#include "../geometry/node_geometry_util.hh"
8
10
11#include "node_function_util.hh"
12
14
16{
17 b.add_input<decl::String>("String"_ustr).optional_label();
18 b.add_input<decl::String>("Separator"_ustr).optional_label();
19 b.add_output<decl::String>("List"_ustr)
20 .structure_type(StructureType::List)
22 "The parts of the input string. This contains at least one element which may be empty");
23}
24
25static Vector<std::string> split_string(const StringRef original_str, const StringRef separator)
26{
27 if (separator.is_empty()) {
28 return {original_str};
29 }
30 StringRef remaining = original_str;
32 while (true) {
33 const int separator_pos = remaining.find(separator);
34 if (separator_pos == StringRef::not_found) {
35 result.append(remaining);
36 return result;
37 }
38 result.append(remaining.substr(0, separator_pos));
39 remaining = remaining.substr(separator_pos + separator.size());
40 }
41}
42
44{
45 const std::string str = params.extract_input<std::string>("String"_ustr);
46 const std::string separator = params.extract_input<std::string>("Separator"_ustr);
47
49 params.set_output("List"_ustr, List<std::string>::from_container(std::move(list)));
50}
51
52static void node_register()
53{
54 static bke::bNodeType ntype;
55
56 fn_node_type_base(&ntype, "FunctionNodeSplitString"_ustr);
57 ntype.ui_name = "Split String";
58 ntype.ui_description = "Split a string into a list using a separator";
60 ntype.declare = node_declare;
63}
65
66} // namespace blender::nodes::node_fn_split_string_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NOD_REGISTER_NODE(REGISTER_FUNC)
static constexpr int64_t not_found
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr int64_t find(char c, int64_t pos=0) const
constexpr StringRef substr(int64_t start, int64_t size) const
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
#define str(s)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static Vector< std::string > split_string(const StringRef original_str, const StringRef separator)
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
void fn_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
NodeDeclareFunction declare
Definition BKE_node.hh:393