You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 lines
726 B

#include "URL.h"
#include "StringUtils.h"
URL::URL(std::string const& url) {
construct(url);
}
std::string URL::toString() {
if (isRelative()) {
return document;
}
return protocol + "://" + host + document;
}
bool URL::isRelative() {
return protocol.size() == 0;
}
void URL::construct(std::string const& url) {
protocol = getProtocolFromURL(url);
if (protocol.size() != 0) {
host = getHostFromURL(url);
document = getDocumentFromURL(url);
} else {
host = "";
document = url;
}
if (document.size() == 0) {
document = "/";
}
}
std::ostream& operator<<(std::ostream& out, URL& url) {
out << url.toString();
return out;
}