-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.cpp
More file actions
35 lines (27 loc) · 777 Bytes
/
Copy pathlib.cpp
File metadata and controls
35 lines (27 loc) · 777 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>
#include <vector>
#include "lib.h"
#include "version.h"
int version() { return PROJECT_VERSION_PATCH; }
Ip_v4::Ip_v4(const std::string &adress) : valid(true) {
for (const std::string &part : split(adress, '.')) {
int int_part = std::stoi(part);
if (is_valid_part(int_part)) {
parts.push_back(int_part);
} else {
valid = false;
}
}
}
std::vector<std::string> split(const std::string &str, char d) {
std::vector<std::string> r;
std::string::size_type start = 0;
std::string::size_type stop = str.find_first_of(d);
while (stop != std::string::npos) {
r.push_back(str.substr(start, stop - start));
start = stop + 1;
stop = str.find_first_of(d, start);
}
r.push_back(str.substr(start));
return r;
}