You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
979 B
37 lines
979 B
#include <string>
|
|
#include "StringTool.h"
|
|
|
|
void StringTool::String2CmdArg(std::string s, std::string & cmd, std::string & arg)
|
|
{
|
|
std::string message = stripWhiteSpace(s);
|
|
if (message.find_first_of(STRING_WHITESPACES, 1) != std::string::npos)
|
|
{
|
|
cmd = stripWhiteSpace(message.substr(0, message.find_first_of(STRING_WHITESPACES, 1)));
|
|
arg = stripWhiteSpace(message.substr(message.find_first_of(STRING_WHITESPACES, 1)));
|
|
} else
|
|
{
|
|
cmd = message;
|
|
arg = "";
|
|
}
|
|
return;
|
|
}
|
|
|
|
std::string StringTool::stripWhiteSpace(std::string s)
|
|
{
|
|
unsigned int i, j;
|
|
if (s.length() > 0)
|
|
{
|
|
i = s.find_first_not_of(STRING_WHITESPACES);
|
|
j = s.find_last_not_of(STRING_WHITESPACES);
|
|
|
|
if (i == std::string::npos)
|
|
i = 0;
|
|
if (j == std::string::npos)
|
|
j = s.length()-1;
|
|
|
|
return std::string(s, i, j-i+1);
|
|
}
|
|
return std::string("");
|
|
}
|
|
|
|
|