| 36 | } |
| 37 | |
| 38 | Words extractWords(std::string_view text, std::string_view separators) |
| 39 | { |
| 40 | Words words; |
| 41 | size_t start{ text.find_first_not_of(separators) }; // Start 1st word |
| 42 | size_t end{}; // Index for the end of a word |
| 43 | |
| 44 | while (start != std::string_view::npos) |
| 45 | { |
| 46 | end = text.find_first_of(separators, start + 1); // Find end separator |
| 47 | if (end == std::string_view::npos) // End of text? |
| 48 | end = text.length(); // Yes, so set to last+1 |
| 49 | words.push_back(text.substr(start, end - start)); |
| 50 | start = text.find_first_not_of(separators, end + 1); // Find next word |
| 51 | } |
| 52 | |
| 53 | return words; |
| 54 | } |
| 55 | |
| 56 | WordCounts countWords(const Words& words) |
| 57 | { |