mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 06:14:59 +00:00
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>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user