Figure 4: Fourth iteration
1: //
2: // Fourth iteration: bid last char *'s farewell by
3: // taking a string &.
4: //
5:
6: template<typename Container>
7: Container make_s(const std::string &intext,
8: bool stripLeadingSpaces = true)
9: {
10: using std::string;
11: Container c;
12: string::const_iterator nextComma;
13:
14: string::const_iterator curPos = intext.begin();
15:
16: while (true)
17: {
18: nextComma = std::find(curPos, intext.end(), ',');
19:
20: if (stripLeadingSpaces)
21: while (curPos != nextComma && isspace(*curPos))
22: ++curPos;
23:
24: c.push_back(string(curPos, nextComma));
25:
26: if (nextComma == intext.end())
27: break;
28:
29: curPos = ++nextComma;
30: }
31:
32: return c;
33: }