Design Pattern Examples
Overview of object-oriented design patterns
splitw.cpp
Go to the documentation of this file.
1
5
6#include "split.h"
7
8namespace Helpers
9{
10
11 // Split the string into multiple strings.
12 std::vector<std::wstring> split(const wchar_t* pszString, const wchar_t* splitChars/* = L" "*/)
13 {
14 std::vector<std::wstring> items;
15 if (splitChars == NULL || *splitChars == L'\0')
16 {
17 splitChars = L" ";
18 }
19
20 const wchar_t* workPtr = pszString;
21 for (;;)
22 {
23 size_t foundIndex = wcscspn(workPtr, splitChars);
24 if (foundIndex < wcslen(workPtr))
25 {
26 items.push_back(std::wstring(workPtr, 0, foundIndex));
27 workPtr += foundIndex + 1;
28 }
29 else
30 {
31 items.push_back(std::wstring(workPtr));
32 break;
33 }
34 }
35 return items;
36 }
37
38 std::vector<std::wstring> split(const std::wstring& szString,
39 const std::wstring& splitChars/* = L" "*/)
40 {
41 return split(szString.c_str(), splitChars.c_str());
42 }
43
44} // end namespace
Declaration of the split functions, for splitting a string on delimiters.
The namespace containing all the "helper" functions in the C++ code.
std::vector< std::string > split(const char *pszString, const char *splitChars)
Split the given string into a list of strings given the character on which to split....
Definition: split.cpp:13