Sha256: 16a1eb4d0af37fb611bcac6e48469ce5673a97d2e5d650fd567c56145e335ff1
Contents?: true
Size: 1.01 KB
Versions: 396
Compression:
Stored size: 1.01 KB
Contents
#include "word_count.h" #include <algorithm> #include <cctype> #include <iterator> #include <vector> #include <boost/algorithm/string.hpp> using namespace std; namespace { string normalize_text(string const& text) { string normalized; transform(text.begin(), text.end(), back_inserter(normalized), [](const char c) { return (isalnum(c) || c == '\'') ? tolower(c) : ' '; }); return normalized; } string trim_word(string const& word) { return boost::trim_copy_if(word, boost::is_any_of("' ")); } vector<string> split_text_into_words(string const& text) { vector<string> words; boost::split(words, text, boost::is_any_of("\t ")); transform(words.begin(), words.end(), words.begin(), trim_word); return words; } } namespace word_count { map<string, int> words(string const& text) { map<string, int> count; for (auto const& word : split_text_into_words(normalize_text(text))) { if (!word.empty()) { ++count[word]; } } return count; } }
Version data entries
396 entries across 396 versions & 1 rubygems