Skip to content

Instantly share code, notes, and snippets.

@sergey-shambir
Last active March 21, 2016 14:45
Show Gist options
  • Save sergey-shambir/bb7b379d0d35a15457cc to your computer and use it in GitHub Desktop.
Save sergey-shambir/bb7b379d0d35a15457cc to your computer and use it in GitHub Desktop.
функция SplitWords на базе boost::trim и boost::split.
// Используем split для разбиения текста на слова
// предикат, возвращённый функцией 'boost::is_space()', отмечает пробельные символы как разделители
// token_compress_on гарантирует склеивание нескольких пробельных символов в один
// 'boost::trim' убирает пробельные символы в начале и в конце (иначе в words окажутся пустые слова).
vector<string> SplitWords(string const& text)
{
std::string trimmed = boost::trim_copy(text);
vector<string> words;
boost::split(words, trimmed, boost::is_space(), boost::token_compress_on);
return words;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment