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

Function extract_words

Examples/Modules/Chapter 08/Ex8_17.cpp:37–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void 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
51void swap(Words& words, size_t first, size_t second)
52{

Callers 7

mainFunction · 0.70
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected