Skip to content

Commit

Permalink
Refactor join function
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Aug 29, 2023
1 parent 59b5851 commit a96f47a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/clib/lib/job_queue/slurm_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,26 @@ static std::string load_stdout(const char *cmd,

static std::vector<std::string> split_string(const std::string &string_value) {
std::vector<std::string> strings;

std::size_t offset = string_value.find_first_not_of(", ");
while (offset != std::string::npos) {
auto item_end = string_value.find_first_of(", ", offset);
strings.push_back(string_value.substr(offset, item_end - offset));
offset = string_value.find_first_not_of(", ", item_end);
}

return strings;
}

template <typename C> static std::string join_string(const C &strings) {
const std::string sep = ",";
std::string full_string;
bool first = true;
for (const auto &s : strings) {
if (!first)
full_string += sep;
full_string += s;
first = false;
std::string str;

for (const auto &key : strings) {
str.append(",");
str.append(key);
}
return full_string;

return str.substr(str.find_first_not_of(','));
}

void *slurm_driver_alloc() {
Expand Down

0 comments on commit a96f47a

Please sign in to comment.