| 26 | } |
| 27 | |
| 28 | void find_words(vector<string>& words, string_view text, string_view separators) |
| 29 | { |
| 30 | size_t start{ text.find_first_not_of(separators) }; // First word start index |
| 31 | |
| 32 | while (start != string_view::npos) // Find the words |
| 33 | { |
| 34 | size_t end{ text.find_first_of(separators, start + 1) }; // Find end of word |
| 35 | if (end == string_view::npos) // Found a separator? |
| 36 | end = text.length(); // No, so set to end of text |
| 37 | |
| 38 | words.push_back(std::string{ text.substr(start, end - start) }); // Store the word |
| 39 | // Or: words.emplace_back(text.substr(start, end - start)); // (in-place construction) |
| 40 | start = text.find_first_not_of(separators, end + 1); // Find 1st character of next word |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void list_words(const vector<string>& words) |
| 45 | { |