- fixed is_local() in Uri
This commit is contained in:
Johannes Schlatow 2010-11-03 13:02:19 +01:00
parent 6cb5c7a104
commit 08bbd38615
2 changed files with 18 additions and 4 deletions

View file

@ -33,6 +33,7 @@ extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Uri::Uri () Uri::Uri ()
{ {
parsed = false;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -46,6 +47,7 @@ Uri::Uri (const Uri& other)
user = other.user; user = other.user;
port = other.port; port = other.port;
protocol = other.protocol; protocol = other.protocol;
parsed = other.parsed;
} }
} }
@ -53,6 +55,7 @@ Uri::Uri (const Uri& other)
Uri::Uri (const std::string& in, const std::string& configPrefix) Uri::Uri (const std::string& in, const std::string& configPrefix)
{ {
data = in; data = in;
parsed = false;
if (configPrefix != "") if (configPrefix != "")
expand(configPrefix); expand(configPrefix);
} }
@ -73,6 +76,7 @@ Uri& Uri::operator= (const Uri& other)
this->user = other.user; this->user = other.user;
this->port = other.port; this->port = other.port;
this->protocol = other.protocol; this->protocol = other.protocol;
this->parsed = other.parsed;
} }
return *this; return *this;
@ -126,9 +130,9 @@ std::string Uri::extension () const
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Uri::is_directory () const bool Uri::is_directory () const
{ {
if (is_local ()) if (is_local ()) {
return Path (this->data).is_directory (); return Path (this->data).is_directory ();
else } else
return (path == ".") return (path == ".")
|| (path == "") || (path == "")
|| (path[path.length()-1] == '/'); || (path[path.length()-1] == '/');
@ -137,6 +141,9 @@ bool Uri::is_directory () const
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Uri::is_local () const bool Uri::is_local () const
{ {
if (parsed)
return (protocol == "");
else
return ( (data.find("://") == std::string::npos) return ( (data.find("://") == std::string::npos)
&& (data.find(":") == std::string::npos) ); && (data.find(":") == std::string::npos) );
} }
@ -180,9 +187,13 @@ bool Uri::expand (const std::string& configPrefix )
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Uri::parse () void Uri::parse ()
{ {
if (parsed)
return;
if (is_local ()) if (is_local ())
{ {
path = data; path = data;
parsed = true;
return; return;
} }
@ -233,6 +244,8 @@ void Uri::parse ()
port = host.substr (pos+1); port = host.substr (pos+1);
host = host.substr (0,pos); host = host.substr (0,pos);
} }
parsed = true;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -62,6 +62,7 @@ public:
std::string port; std::string port;
std::string user; std::string user;
std::string protocol; std::string protocol;
bool parsed;
}; };
#endif #endif