Example #1
0
LWRESULT Cx_ConsoleMgr::PraseCommandLine(const std::string& command_str, COMMAND_LINE& command_line,
												const std::string& div_char)
{
	std::string match(div_char);
	bool removeEmpty = true;
    std::string::size_type start = 0;           // starting position for searches
    std::string::size_type skip  = 1;            // positions to skip after a match

	command_line.clear();
    skip = match.length();
    while (start != std::string::npos)
    {
        // get a complete range [start..end)
        std::string::size_type end = command_str.find_first_of(match, start);

        // null strings always match in string::find, but
        // a skip of 0 causes infinite loops. pretend that
        // no tokens were found and extract the whole string
        if (skip == 0) end = std::string::npos;

        std::string token = command_str.substr(start, end - start);

        if (!(removeEmpty && token.empty()))
        {
            // extract the token and add it to the result list
            command_line.push_back(token);
        }

        // start the next range
        if ((start = end) != std::string::npos) start += skip;
    }

	return LWDP_OK;
}