mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +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:
39
workflow/plugins/cpp/string/string_split/string_split.hpp
Normal file
39
workflow/plugins/cpp/string/string_split/string_split.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
/**
|
||||
* Workflow plugin: split string by separator
|
||||
*/
|
||||
|
||||
#include "../../plugin.hpp"
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
namespace metabuilder::workflow::string {
|
||||
|
||||
inline PluginResult split(Runtime&, const json& inputs) {
|
||||
auto text = inputs.value("text", std::string{});
|
||||
auto separator = inputs.value("separator", std::string{" "});
|
||||
auto max_splits = inputs.contains("max_splits") ? inputs["max_splits"].get<int>() : -1;
|
||||
|
||||
std::vector<std::string> result;
|
||||
|
||||
if (separator.empty()) {
|
||||
result.push_back(text);
|
||||
return {{"result", result}};
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
size_t prev = 0;
|
||||
int count = 0;
|
||||
|
||||
while ((pos = text.find(separator, prev)) != std::string::npos) {
|
||||
if (max_splits >= 0 && count >= max_splits) break;
|
||||
result.push_back(text.substr(prev, pos - prev));
|
||||
prev = pos + separator.length();
|
||||
++count;
|
||||
}
|
||||
result.push_back(text.substr(prev));
|
||||
|
||||
return {{"result", result}};
|
||||
}
|
||||
|
||||
} // namespace metabuilder::workflow::string
|
||||
Reference in New Issue
Block a user