forked from liranbg/jceConnection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPage.cpp
More file actions
133 lines (126 loc) · 2.29 KB
/
Copy pathPage.cpp
File metadata and controls
133 lines (126 loc) · 2.29 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
#include "Page.h"
Page::Page(string& html)
{
cout << "bulding page... string size: " << html.length() << endl;
if(html.empty())
cout << "ERROR: unable to build Page" << endl;
makeText(html);
}
Page::~Page()
{
cout << "killing Page..." <<endl;
}
void Page::makeText(string& html)
{
bool foundTitle = false;
bool inBody = false;
string temp = "";
for (int i = 0; i < html.length() ; i++)
{
if(!foundTitle)
{
if(html[i] == '<')
{
//title>
i++;
string titleTag = html.substr(i, 5); //legth of title
if(titleTag == "title") //check if the tag is title
{
while(html[i] != '>')
i++;
i++;
while(html[i] != '<')
{
temp += html[i];
i++;
}
foundTitle = true;
this->title = temp;
}
}
temp = "" ; //clear temp BUFFER
}
else
{
if(html[i] == '<')
{
//body>
i++;
string bodyTag = html.substr(i, 4); //legth of "body"
if(bodyTag == "body") //check if the tag is body tag
{
while(html[i] != '>')
i++;
inBody = true;
}
}
}
/**
* Actual Body Text In String
*/
if(inBody)
{
if(html[i] == '<')
{
//tr> / td>
i++;
string tableTag = html.substr(i, 2); //legth of "tr/td"
if(tableTag == "tr")
{
temp += "\n"; //new row -> new line
while(html[i] != '>')
i++;
i++;
}
else if(tableTag == "td")
{
temp += "\t"; // new cell -> tab between data
while(html[i] != '>')
i++;
i++;
}
}
if(html[i] == '>')
{
i++;
if(endOfString(i, html.length()))
goto finishBuild; //Cheak if EOF (Text)
while(html[i] != '<')
{
if(endOfString(i, html.length()))
goto finishBuild; //Cheak if EOF (Text)
if(html[i] == '&')
{
//
string nbspChr = html.substr(i, 6);
if(nbspChr == " ")
i += 6;
if(endOfString(i, html.length()))
goto finishBuild; //Cheak if EOF (Text)
}
if(html[i] == '<')
continue;
else if(html[i] != '\n')
temp += html[i];
i++;
}
}
}
}
finishBuild:
this->text = temp;
}
bool Page::endOfString(int index, int length)
{
if(index < length)
return false;
return true;
}
string Page::getString()
{
return this->text;
}
string Page::getTitle()
{
return this->title;
}