-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.txt
More file actions
140 lines (122 loc) · 3.02 KB
/
Copy pathParser.txt
File metadata and controls
140 lines (122 loc) · 3.02 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream> //https://stackoverflow.com/questions/13428164/c-compile-error-has-initializer-but-incomplete-type
class http_server {
private:
// vector of servers
};
void parsing(std::ifstream& config_file) {
/*
void parsing(std::string str) {
std::string::iterator it;
std::size_t pos;
for(it = str.begin(); it < str.end(); it++)
{
if (pos = (str+it).find("server", it, 6));
{
std::cout << str.substr(pos, pos+6) << std::endl;
it += 6;
}
}
*/
std::string str;
//https://www.geeksforgeeks.org/tokenizing-a-string-cpp/?ref=lbp
while (getline(config_file, str))
{
/*
//skip_whitespaces(str);
// use iterators in string
std::size_t pos;
pos = str.find("server");
//https://www.geeksforgeeks.org/string-find-in-cpp/
if ( pos != std::string::npos)
std::cout << str.substr(pos, pos+7) << std::endl;
//else
// std::cout << str << std::endl;
*/
/* std::vector<std::string>& strtock_one_del(std::string& str, char c)
{
std::stringstream check_serverblock(str);
std::string intermediate;
std::vector<std::string> tokens;
while (getline(check_serverblock, intermediate, c))
{
tokens.push_back(intermediate);
}
}
std::vector<std::string>& strtock_multi_del(std::string& str, std::string& del)
{
std::stringstream check_serverblock(str);
std::string intermediate;
std::vector<std::string> tokens;
while (getline(check_serverblock, intermediate, del[1]))
{
tokens.push_back(intermediate);
}
}
*/
if (str.substr(0, 6) == "server")
{
//strtock()
}
else
{
std::stringstream check_serverblock(str);
std::string intermediate;
std::vector<std::string> tokens;
// Tokenizing with space
while (getline(check_serverblock, intermediate, ' '))
{
tokens.push_back(intermediate);
}
// Printing the token vector
for (int i = 0; i < tokens.size(); i++)
std::cout << tokens[i] << std::endl;
}
}
}
int parser(std::string arg, http_server& web_server)
{
// This method using push_back : reference/string/string/push_back
/* std::string str;
std::ifstream file;
file.open(arg, std::ios::in);
if (file.is_open())
{
while (!file.eof())
str.push_back(file.get());
parsing(str);
}
else
{
std::cout << "Error opening file";
throw 501;
}
return (0);
*/
std::ifstream config_file;
config_file.open(arg, std::ifstream::in);
if (config_file.is_open())
{
// use seekg() to go til the end of the file
config_file.seekg(0, std::ifstream::end);
if (config_file.tellg() == EOF)
std::cout << "ERROR empty file: " << arg << std::endl;
else
{
// use seekg() to comeback to the beg of the file
config_file.seekg(0, std::ifstream::beg);
std::cout << "Now you need to parse it to tokens" << std::endl;
parsing(config_file); //https://stackoverflow.com/questions/27501160/pass-a-reference-to-stdifstream-as-parameter
}
config_file.close();
}
else
{
std::cout << "ERROR opening file: " << arg << std::endl;
throw 501;
}
return (0);
}