Blender V5.3
node_fn_reverse_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
8#include "node_shader_util.hh"
9
11
13{
14 b.is_function_node();
15 b.use_custom_socket_order();
16 b.allow_any_socket_order();
17 b.add_input<decl::String>("String"_ustr).optional_label();
18 b.add_output<decl::String>("String"_ustr).align_with_previous();
19}
20
22{
23 static auto reverse_fn = mf::build::SI1_SO<std::string, std::string>(
24 "Reverse", [](const std::string &s) {
25 if (s.empty()) {
26 return std::string();
27 }
28 std::string result;
29 result.reserve(s.size());
30
31 const char *start = s.data();
32 const char *curr = start + s.size();
33 while (curr > start) {
34 const char *prev = BLI_str_find_prev_char_utf8(curr, start);
35 size_t char_len = curr - prev;
36 result.append(prev, char_len);
37 curr = prev;
38 }
39 return result;
40 });
41 builder.set_matching_fn(&reverse_fn);
42}
43
44static void node_register()
45{
46 static bke::bNodeType ntype;
47
48 common_node_type_base(&ntype, "FunctionNodeReverseString"_ustr);
49 ntype.ui_name = "Reverse String";
50 ntype.ui_description = "Reverse the order of the characters in a string";
52 ntype.declare = node_declare;
55}
57
58} // namespace blender::nodes::node_fn_reverse_string_cc
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
static void node_declare(NodeDeclarationBuilder &b)
const char * BLI_str_find_prev_char_utf8(const char *p, const char *str_start) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
void common_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
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
NodeDeclareFunction declare
Definition BKE_node.hh:393