-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenizer.cpp
More file actions
79 lines (51 loc) · 1.41 KB
/
tokenizer.cpp
File metadata and controls
79 lines (51 loc) · 1.41 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <sstream>
#include <string>
#include <string_view>
#include <iterator>
void no_delim(std::string const& str) {
std::istringstream iss{str};
std::string word;
while(iss) {
iss >> word;
if (!word.empty())
std::cout << word << std::endl;
word = "";
}
}
void with_delim(std::string const& str, char delim) {
std::istringstream iss{str};
std::string word;
while(std::getline(iss, word, delim)){
std::cout << word << std::endl;
}
}
void no_delim_iterator(std::string const& str) {
std::istringstream iss{str};
std::istream_iterator<std::string> itr{iss}, end;
while(itr != end) {
std::cout << *itr++ << std::endl;
}
}
void with_find(std::string_view str) {
std::string_view delims = " :;";
auto beg = 0, end = 0;
while((beg = str.find_first_not_of(delims, end)) != std::string::npos) {
end = str.find_first_of(delims, beg);
std::cout << str.substr(beg, end-beg) << std::endl;
}
}
int main() {
std::string text = " fdfds fdfd f ds fds af ds f dsa fds ";
no_delim(text);
std::cout << std::endl;
no_delim_iterator(text);
std::cout << std::endl;
with_delim(text,' ');
std::cout << std::endl;
text = "fdsff:fdsafsd;fdsafdsaf;fdafdsa";
with_delim(text,';');
std::cout << std::endl;
with_find(text);
return 0;
}