MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / extract_words

Function extract_words

Examples/NoModules/Chapter 08/Ex8_17.cpp:36–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.70

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected