Integrate in agent.
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
#include "envmanager.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
@ -97,20 +98,6 @@ void envmanager::clear_variables() {
|
||||
m_variables.clear();
|
||||
}
|
||||
|
||||
std::string trim(std::string str) {
|
||||
// Trim leading whitespace
|
||||
str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
|
||||
// Trim trailing whitespace
|
||||
str.erase(std::find_if(str.rbegin(), str.rend(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}).base(), str.end());
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string envmanager::expand_patterns(std::string str) const {
|
||||
// Combined regex pattern for both ${var} and $var formats
|
||||
std::regex var_pattern("\\$(?:\\{([^}]+)\\}|([a-zA-Z0-9_]+))");
|
||||
@ -132,62 +119,4 @@ std::string envmanager::expand_patterns(std::string str) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string multi2string(std::vector<std::string> values)
|
||||
{
|
||||
std::string result;
|
||||
for (const auto& value : values) {
|
||||
// remove any " contained in the string value, if present
|
||||
std::string quoteless_value = value;
|
||||
quoteless_value.erase(std::remove(quoteless_value.begin(), quoteless_value.end(), '"'), quoteless_value.end());
|
||||
result += "\"" + trim(quoteless_value) + "\",";
|
||||
}
|
||||
if (!result.empty())
|
||||
result.pop_back(); // Remove the last comma
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> string2multi(std::string values)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
|
||||
// Return values separated by commas, but ignore commas within quotes
|
||||
bool inside_quotes = false;
|
||||
std::string current_item;
|
||||
|
||||
for (char c : values) {
|
||||
if (c == '"') {
|
||||
inside_quotes = !inside_quotes;
|
||||
} else if (c == ',' && !inside_quotes) {
|
||||
if (!current_item.empty()) {
|
||||
// Remove quotes if present
|
||||
if (current_item.front() == '"' && current_item.back() == '"') {
|
||||
current_item = current_item.substr(1, current_item.length() - 2);
|
||||
}
|
||||
std::string final = trim(current_item);
|
||||
if (!final.empty()) {
|
||||
result.push_back(final);
|
||||
}
|
||||
current_item.clear();
|
||||
}
|
||||
} else {
|
||||
current_item += c;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the last item if not empty
|
||||
if (!current_item.empty()) {
|
||||
// Remove quotes if present
|
||||
if (current_item.front() == '"' && current_item.back() == '"') {
|
||||
current_item = current_item.substr(1, current_item.length() - 2);
|
||||
}
|
||||
std::string final = trim(current_item);
|
||||
if (!final.empty()) {
|
||||
result.push_back(final);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
||||
|
Reference in New Issue
Block a user