#include "URL.h"
URL::URL() : url(""), title(""), description("") {
}
URL::~URL()
{
}
URL::URL(string & u) : url(u), title(""), description("")
{
}
URL::URL(string &u, string &t, string &d) : url(u), title(t), description(d)
{
}
URL::URL(const URL &u) : url(u.url), title(u.title), description(u.description)
{
}
ostream & operator<<(ostream & os, const URL & u){
os << "<a href=\"" << u.url << "\">" << u.title
<< "</a>";
if (u.description != "")
os << "- "<< u.description;
os << "<br>";
return os;
}
int URL::operator ==(const URL &u) const
{
return (url == u.url);
}
istream & operator >>(istream &is, URL &u)
{
const string urlBegin = "<ExternalPage about=\"";
const string urlEnd = "\">";
const string pageEnd = "</ExternalPage>"; const string titleBegin = "<d:Title>";
const string titleEnd = "</d:Title>";
const string descBegin = "<d:Description>";
const string descEnd = "</d:Description>";
string::size_type start;
string::size_type end;
string line;
u.url = "";
u.title = "";
u.description = "";
while (getline (is, line)) { start = line.find(urlBegin); if (start != string::npos) {
start += urlBegin.size();
end = line.find(urlEnd);
u.url = line.substr(start, end-start);
continue;
}
start = line.find(titleBegin);
if (start != string::npos){
start+= titleBegin.size();
end = line.find(titleEnd);
u.title = line.substr(start, end-start);
continue;
}
start = line.find(descBegin);
if (start != string::npos){
start+=descBegin.size();
end = line.find(descEnd);
u.description = line.substr(start, end-start);
}
start = line.find(pageEnd);
if (start != string::npos)
break; }
return is;
}