| 35 | } |
| 36 | |
| 37 | void extract_words(Words& words, const std::string& text, const std::string& separators) |
| 38 | { |
| 39 | size_t start {text.find_first_not_of(separators)}; // Start index of first word |
| 40 | |
| 41 | while (start != std::string::npos) |
| 42 | { |
| 43 | size_t end{ text.find_first_of(separators, start + 1) }; // Find end of a word |
| 44 | if (end == std::string::npos) // Found a separator? |
| 45 | end = text.length(); // Yes, so set to end of text |
| 46 | words.push_back(std::make_shared<std::string>(text.substr(start, end - start))); |
| 47 | start = text.find_first_not_of(separators, end + 1); // Find start next word |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void swap(Words& words, size_t first, size_t second) |
| 52 | { |