Files
metabuilder/workflow/plugins/cpp/string/string_replace/string_replace.hpp
johndoe6345789 c1352c4bea refactor: Restructure multi-language workflow plugins to match Python pattern
Each plugin now follows the standardized structure:
- category/plugin_name/plugin_name.{ext} - Implementation
- category/plugin_name/package.json - Plugin metadata
- category/package.json - Category manifest with "plugins" array

Languages restructured:
- Go: 31 plugins across 7 categories (math, string, logic, list, dict, var, convert)
- Rust: 55 plugins as individual crates in Cargo workspace
- C++: 34 header-only plugins with complete coverage
- Mojo: 11 plugins across 3 categories (math, string, list)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 19:10:09 +00:00

35 lines
906 B
C++

#pragma once
/**
* Workflow plugin: replace occurrences in string
*/
#include "../../plugin.hpp"
namespace metabuilder::workflow::string {
inline PluginResult replace(Runtime&, const json& inputs) {
auto text = inputs.value("text", std::string{});
auto old_str = inputs.value("old", std::string{});
auto new_str = inputs.value("new", std::string{});
auto count = inputs.contains("count") ? inputs["count"].get<int>() : -1;
if (old_str.empty()) {
return {{"result", text}};
}
std::string result = text;
size_t pos = 0;
int replaced = 0;
while ((pos = result.find(old_str, pos)) != std::string::npos) {
if (count >= 0 && replaced >= count) break;
result.replace(pos, old_str.length(), new_str);
pos += new_str.length();
++replaced;
}
return {{"result", result}};
}
} // namespace metabuilder::workflow::string