150 |
|
|
151 |
|
return os; |
152 |
|
} |
153 |
+ |
|
154 |
+ |
string getLink(string link, URL& url) |
155 |
+ |
{ |
156 |
+ |
string hyperlink = ""; |
157 |
+ |
|
158 |
+ |
if (link.find('#') != string::npos) |
159 |
+ |
{ |
160 |
+ |
unsigned pound = link.find('#'); |
161 |
+ |
link.erase(pound); |
162 |
+ |
} |
163 |
+ |
|
164 |
+ |
if (link.find("://") != string::npos) |
165 |
+ |
{ |
166 |
+ |
if (link.find("http://") == 0) hyperlink = link; |
167 |
+ |
} |
168 |
+ |
else if (link.find("mailto:") == 0) |
169 |
+ |
{ |
170 |
+ |
// do nothing we are not evil spammers! |
171 |
+ |
} |
172 |
+ |
else if (link.find("//") == 0) |
173 |
+ |
{ |
174 |
+ |
hyperlink = "http:" + link; |
175 |
+ |
} |
176 |
+ |
else if (link.find('/') == 0) |
177 |
+ |
{ |
178 |
+ |
hyperlink = url.getURL(); |
179 |
+ |
|
180 |
+ |
unsigned path = hyperlink.find('/', 7); |
181 |
+ |
hyperlink.erase(path); |
182 |
+ |
|
183 |
+ |
hyperlink += link; |
184 |
+ |
} |
185 |
+ |
else if (link == "") |
186 |
+ |
{ |
187 |
+ |
// a blank link is useless |
188 |
+ |
} |
189 |
+ |
else |
190 |
+ |
{ |
191 |
+ |
hyperlink = url.getURL(); |
192 |
+ |
string path = url.getPath(); |
193 |
+ |
|
194 |
+ |
unsigned cutoff = hyperlink.rfind(path); |
195 |
+ |
hyperlink.erase(cutoff); |
196 |
+ |
|
197 |
+ |
unsigned dir = path.rfind('/') + 1; |
198 |
+ |
path.erase(dir); |
199 |
+ |
|
200 |
+ |
while (link.find("../") == 0) |
201 |
+ |
{ |
202 |
+ |
unsigned dot = path.rfind('/') - 1; |
203 |
+ |
unsigned up = path.rfind('/', dot) + 1; |
204 |
+ |
|
205 |
+ |
path.erase(up); |
206 |
+ |
link.erase(0, 3); |
207 |
+ |
} |
208 |
+ |
while (link.find("./") == 0) |
209 |
+ |
{ |
210 |
+ |
link.erase(0, 2); |
211 |
+ |
} |
212 |
+ |
|
213 |
+ |
hyperlink += path + link; |
214 |
+ |
} |
215 |
+ |
|
216 |
+ |
return hyperlink; |
217 |
+ |
} |