Blender V4.3
node_fn_slice_string.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_string_utf8.h"
6
8
10
12{
13 b.add_input<decl::String>("String").hide_label();
14 b.add_input<decl::Int>("Position");
15 b.add_input<decl::Int>("Length").min(0).default_value(10);
16 b.add_output<decl::String>("String");
17}
18
20{
21 static auto slice_fn = mf::build::SI3_SO<std::string, int, int, std::string>(
22 "Slice", [](const std::string &str, int a, int b) {
23 const int start = BLI_str_utf8_offset_from_index(str.c_str(), str.size(), std::max(0, a));
24 const int end = BLI_str_utf8_offset_from_index(
25 str.c_str(), str.size(), std::max(0, a + b));
26 return str.substr(start, std::max<int>(end - start, 0));
27 });
28 builder.set_matching_fn(&slice_fn);
29}
30
31static void node_register()
32{
33 static blender::bke::bNodeType ntype;
34
35 fn_node_type_base(&ntype, FN_NODE_SLICE_STRING, "Slice String", NODE_CLASS_CONVERTER);
36 ntype.declare = node_declare;
39}
41
42} // namespace blender::nodes::node_fn_slice_string_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
int BLI_str_utf8_offset_from_index(const char *str, size_t str_len, int index_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
local_group_size(16, 16) .push_constant(Type b
#define str(s)
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_declare(NodeDeclarationBuilder &b)
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
void fn_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition sort.c:32
Defines a node type.
Definition BKE_node.hh:218
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:336
NodeDeclareFunction declare
Definition BKE_node.hh:347