#include "Utils.h" namespace Utils { std::vector SplitText(const std::string text, char separator = ' ', bool keep_quotes = false) { std::vector args; char* input = _strdup(text.c_str()); const size_t length = strlen(input); bool inQuotes = false; size_t count = 0, from = 0; for (size_t i = 0; i < length; i++) { if (input[i] == '"') { inQuotes = !inQuotes; } else if (input[i] == separator && !inQuotes) { size_t strlen = i - from; if (strlen > 0) { if (!keep_quotes && input[from] == '"' && input[i - 1] == '"') { from++; strlen -= 2; } char* tmp = new char[strlen + 1](); strncpy(tmp, &input[from], strlen); count++; args.emplace_back(tmp); } from = i + 1; } } if (from < length) { size_t strlen = length - from; if (!keep_quotes && input[from] == L'"' && input[length - 1] == L'"') { from++; strlen -= 2; } char* tmp = new char[strlen + 1](); strncpy(tmp, &input[from], strlen); count++; args.emplace_back(tmp); } return args; } }