Repository navigation
Expand file tree
/
Copy pathparse_addr.cpp
More file actions
executable file
·59 lines (49 loc) · 1.52 KB
/
Copy pathparse_addr.cpp
File metadata and controls
executable file
·59 lines (49 loc) · 1.52 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
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string.h>
#include <ctime>
using namespace std;
const std::string WHITESPACE = " \n\r\f\v";
std::string ltrim(const std::string &s)
{
size_t start = s.find_first_not_of(WHITESPACE);
return (start == std::string::npos) ? "" : s.substr(start);
}
std::string rtrim(const std::string &s)
{
size_t end = s.find_last_not_of(WHITESPACE);
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
}
std::string trim(const std::string &s) {
return rtrim(ltrim(s));
}
bool startsWith(std::string mainStr, std::string toMatch)
{
// std::string::find returns 0 if toMatch is found at starting
if(mainStr.find(toMatch) == 0)
return true;
else
return false;
}
int main() {
time_t seconds; struct tm *timeStruct;
string line;
ifstream ReadFile("address.tsv");
ofstream WriteFile("address_parsed.txt", std::ios_base::app);
seconds = time(NULL);
timeStruct = localtime(&seconds);
printf("[%02d:%02d:%02d] Start parsing address file\n", timeStruct->tm_hour, timeStruct->tm_min, timeStruct->tm_sec);
while (getline(ReadFile, line)) {
line = trim(line);
if(startsWith(line, "1")) {
WriteFile << line << '\n';
}
}
seconds = time(NULL);
timeStruct = localtime(&seconds);
printf("[%02d:%02d:%02d] Finish parsing address file\n", timeStruct->tm_hour, timeStruct->tm_min, timeStruct->tm_sec);
ReadFile.close();
WriteFile.close();
return 0;
}