Skip to content

Commit

Permalink
Removing unsafe C function usage #BG-167
Browse files Browse the repository at this point in the history
  • Loading branch information
gamedev8 committed Feb 3, 2024
1 parent f896344 commit 68749e7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions server/StringUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ namespace gazellemq::utils {
* @return
*/
void split(std::string &&input, std::vector<std::string>& strings, std::string &&prefix = "", char delimiter = ',') {
char *s = input.data();
char *word = strtok(s, &delimiter);
std::string buf;
buf.reserve(input.size());

while (word) {
std::string val{prefix};
val.append(word);
strings.emplace_back(std::move(val));
word = strtok(nullptr, &delimiter);
for (size_t i{}; i < input.size(); ++i) {
if (input[i] != ',') {
buf.push_back(input[i]);
} else {
strings.push_back(std::move(std::string{buf}));
buf.clear();
}
}

if (!buf.empty()) {
strings.push_back(std::move(buf));
}
input.clear();
}
}

Expand Down

0 comments on commit 68749e7

Please sign in to comment.