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

Function extractWords

Examples/NoModules/Chapter 20/Ex20_05/Ex20_05.cpp:38–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38Words 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
56WordCounts countWords(const Words& words)
57{

Callers 1

mainFunction · 0.70

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected