-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.cpp
More file actions
35 lines (29 loc) · 939 Bytes
/
Copy pathUtility.cpp
File metadata and controls
35 lines (29 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "Utility.hpp"
using namespace std;
vector<string> split_line(const string& s, const vector<char>& delim)
{
vector<string> words;
typedef string::size_type string_size;
string_size i = 0;
// invariant: we have processed characters `['original value of `i', `i)'
while (i < s.size())
{
// ignore leading blanks
// invariant: characters in range `['original `i', current `i)' are all spaces
while (i < s.size() && (isspace(s[i]) || contains(delim, s[i])))
++i;
// find end of next word
string_size j = i;
// invariant: none of the characters in range `['original `j', current `j)' is a space
while (j < s.size() && !isspace(s[j]) && !contains(delim, s[j]))
++j;
// if we found some nonwhitespace characters
if (i < j)
{
// copy from `s' starting at `i' and taking `j' `\-' `i' chars
words.push_back(s.substr(i, j - i));
i = j;
}
}
return words;
}