void tokenizeWords(const Glib::ustring& str, std::vector<Glib::ustring>& container) { ustring::size_type lastPos = str.find_first_not_of(' ', 0); ustring::size_type pos = str.find_first_of(' ', lastPos); while (ustring::npos != pos || ustring::npos != lastPos) { container.push_back(str.substr(lastPos, pos - lastPos)); lastPos = str.find_first_not_of(' ', pos); pos = str.find_first_of(' ', lastPos); } }
void vTokenize(Glib::ustring source, std::vector<Glib::ustring>& tokens) { Glib::ustring delimiters = " \t\n\r"; // Skip delimiters at beginning. Glib::ustring::size_type lastPos = source.find_first_not_of(delimiters, 0); // Find first "non-delimiter". Glib::ustring::size_type pos = source.find_first_of(delimiters, lastPos); while (Glib::ustring::npos != pos || std:: string::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(source.substr(lastPos, pos - lastPos)); // Skip delimiters. Note the "not_of" lastPos = source.find_first_not_of(delimiters, pos); // Find next "non-delimiter" pos = source.find_first_of(delimiters, lastPos); } }
void ViCommandMode::execute_command(const Glib::ustring &cmd_line) { // TODO: more intelligent parsing Glib::ustring cmd; int idx = cmd_line.find_first_of(' '); if (idx > 0) { m_cmd_params = cmd_line.substr(idx+1); cmd = cmd_line.substr(0, idx); } else { cmd = cmd_line; m_cmd_params = ""; } g_print("Command %s with params '%s'\n", cmd.data(), m_cmd_params.data()); ExecutableAction *act = m_commandMap[cmd]; if (act) { act->execute(); } }