Multiple directories

This commit is contained in:
Your Name
2025-04-25 17:42:02 +12:00
parent 4d3523a346
commit 72e757ebd6
14 changed files with 344 additions and 113 deletions

View File

@ -97,7 +97,7 @@ void envmanager::clear_variables() {
m_variables.clear();
}
std::string envmanager::trim(std::string str) const {
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);
@ -132,4 +132,62 @@ 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