| 101 | } |
| 102 | |
| 103 | Words extractWords(std::string_view text, std::string_view separators) |
| 104 | { |
| 105 | Words words; |
| 106 | size_t start{ text.find_first_not_of(separators) }; // Start 1st word |
| 107 | size_t end{}; // Index for the end of a word |
| 108 | |
| 109 | while (start != std::string_view::npos) |
| 110 | { |
| 111 | end = text.find_first_of(separators, start + 1); // Find end separator |
| 112 | if (end == std::string_view::npos) // End of text? |
| 113 | end = text.length(); // Yes, so set to last+1 |
| 114 | words.push_back(text.substr(start, end - start)); |
| 115 | start = text.find_first_not_of(separators, end + 1); // Find next word |
| 116 | } |
| 117 | |
| 118 | return words; |
| 119 | } |
| 120 | |
| 121 | WordCounts countWords(const Words& words) |
| 122 | { |