-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_processing.cpp
More file actions
35 lines (29 loc) · 848 Bytes
/
Copy pathstring_processing.cpp
File metadata and controls
35 lines (29 loc) · 848 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 "string_processing.h"
#include <sstream>
using namespace std;
vector<string> SplitIntoWords(const string &text) {
vector<string> words;
string word;
std::istringstream iss(text, std::istringstream::in);
while(iss >> word) {
words.push_back(word);
}
return words;
}
vector<string_view> SplitIntoWordsView(string_view str) {
vector<string_view> result;
const int64_t pos_end = static_cast<int64_t>(str.npos);
while (true) {
int64_t space = static_cast<int64_t>(str.find(' '));
string_view s = str.substr(0, static_cast<size_t>(space));
if (!s.empty()) {
result.push_back(s);
}
if (space == pos_end) {
break;
} else {
str.remove_prefix(static_cast<size_t>(space+1));
}
}
return result;
}