split fixed
This commit is contained in:
parent
fd011571bc
commit
40340324d3
1 changed files with 16 additions and 16 deletions
|
|
@ -27,26 +27,26 @@
|
||||||
* @param channel channel where the command is sent
|
* @param channel channel where the command is sent
|
||||||
* @param line line send by the user
|
* @param line line send by the user
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::vector<std::string> cmd::split(std::string &line) {
|
std::vector<std::string> cmd::split(std::string &line) {
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
std::string arg;
|
size_t start = 0;
|
||||||
if (line.empty())
|
size_t end;
|
||||||
return args;
|
|
||||||
size_t pos = line.find(' ');
|
while ((end = line.find(' ', start)) != std::string::npos) {
|
||||||
size_t old_pos = 0;
|
std::string arg = line.substr(start, end - start);
|
||||||
while (pos != std::string::npos) {
|
if (!arg.empty()) {
|
||||||
arg = line.substr(old_pos, pos);
|
for (size_t i = 0; i < arg.length(); ++i)
|
||||||
if (arg.empty()) {
|
arg[i] = std::tolower(arg[i]);
|
||||||
break;
|
args.push_back(arg);
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < arg.length(); i++)
|
start = end + 1;
|
||||||
arg = std::tolower(line[i]);
|
|
||||||
args.push_back(arg);
|
|
||||||
old_pos = pos;
|
|
||||||
pos = line.find(' ', old_pos + 1);
|
|
||||||
}
|
}
|
||||||
if (!line.empty()) {
|
if (start < line.length()) {
|
||||||
return args;
|
std::string arg = line.substr(start);
|
||||||
|
for (size_t i = 0; i < arg.length(); ++i)
|
||||||
|
arg[i] = std::tolower(arg[i]);
|
||||||
|
args.push_back(arg);
|
||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue