Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2022-05-24 11:21:02 +0300
committerJacques Lucke <jacques@blender.org>2022-05-24 11:21:02 +0300
commit174c3ffb4adf29e0a7698aacf9468a820f448770 (patch)
treef097c7055de9a621b817dd1098995dffa236091d /source/blender/nodes
parent2ea6a0dd4d8e93012fde357f745691095a047123 (diff)
Fix T98268: replace string node des not handle empty strings correctly
Just use an existing function from blenlib instead of implementing a new version.
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/function/nodes/node_fn_replace_string.cc18
1 files changed, 8 insertions, 10 deletions
diff --git a/source/blender/nodes/function/nodes/node_fn_replace_string.cc b/source/blender/nodes/function/nodes/node_fn_replace_string.cc
index 6abcc79cf29..4b493438a45 100644
--- a/source/blender/nodes/function/nodes/node_fn_replace_string.cc
+++ b/source/blender/nodes/function/nodes/node_fn_replace_string.cc
@@ -15,19 +15,17 @@ static void fn_node_replace_string_declare(NodeDeclarationBuilder &b)
b.add_output<decl::String>(N_("String"));
}
-static std::string replace_all(std::string str, const std::string &from, const std::string &to)
+static std::string replace_all(const StringRefNull str,
+ const StringRefNull from,
+ const StringRefNull to)
{
- if (from.length() <= 0) {
+ if (from.is_empty()) {
return str;
}
- const size_t step = to.length() > 0 ? to.length() : 1;
-
- size_t offset = 0;
- while ((offset = str.find(from, offset)) != std::string::npos) {
- str.replace(offset, from.length(), to);
- offset += step;
- }
- 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 fn_node_replace_string_build_multi_function(NodeMultiFunctionBuilder &builder)