Files
test2/source/blender/nodes/function/nodes/node_fn_replace_string.cc
Damien Picard 22f641e7f8 Cleanup: I18n: Remove extraction macros from node socket declarations
The previous two commits introduced new regexes to extract node socket
names and descriptions automatically from the i18n Python module,
including socket labels.

This commit removes the extraction macros from all node files since
they are now redundant.

Pull Request: https://projects.blender.org/blender/blender/pulls/107258
2023-05-16 14:12:54 +02:00

52 lines
1.6 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_string_utf8.h"
#include "node_function_util.hh"
namespace blender::nodes::node_fn_replace_string_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::String>("String");
b.add_input<decl::String>("Find").description("The string to find in the input string");
b.add_input<decl::String>("Replace").description("The string to replace each match with");
b.add_output<decl::String>("String");
}
static std::string replace_all(const StringRefNull str,
const StringRefNull from,
const StringRefNull to)
{
if (from.is_empty()) {
return str;
}
char *new_str_ptr = BLI_str_replaceN(str.c_str(), from.c_str(), to.c_str());
std::string new_str{new_str_ptr};
MEM_freeN(new_str_ptr);
return new_str;
}
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
{
static auto substring_fn = mf::build::SI3_SO<std::string, std::string, std::string, std::string>(
"Replace", [](const std::string &str, const std::string &find, const std::string &replace) {
return replace_all(str, find, replace);
});
builder.set_matching_fn(&substring_fn);
}
} // namespace blender::nodes::node_fn_replace_string_cc
void register_node_type_fn_replace_string()
{
namespace file_ns = blender::nodes::node_fn_replace_string_cc;
static bNodeType ntype;
fn_node_type_base(&ntype, FN_NODE_REPLACE_STRING, "Replace String", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::node_declare;
ntype.build_multi_function = file_ns::node_build_multi_function;
nodeRegisterType(&ntype);
}