X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/93bf083d699c60f1ac40297bfa6783fb0cb800d8..db890fdba13d88ef85a2ac0ce39749ebfa835516:/apt-pkg/contrib/strutl.cc diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index d6a7143e4..499b72a5e 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: strutl.cc,v 1.9 1998/10/30 07:53:45 jgg Exp $ +// $Id: strutl.cc,v 1.15 1998/12/04 21:16:50 jgg Exp $ /* ###################################################################### String Util - Some usefull string functions. @@ -15,13 +15,16 @@ ##################################################################### */ /*}}}*/ // Includes /*{{{*/ +#ifdef __GNUG__ +#pragma implementation "strutl.h" +#endif + #include #include #include #include #include -#include /*}}}*/ // strstrip - Remove white space from the front and back of a string /*{{{*/ @@ -609,10 +612,10 @@ bool StrToTime(string Val,time_t &Result) } /*}}}*/ -// URI::URI - Constructor /*{{{*/ +// URI::CopyFrom - Copy from an object /*{{{*/ // --------------------------------------------------------------------- /* This parses the URI into all of its components */ -URI::URI(string U) +void URI::CopyFrom(string U) { string::const_iterator I = U.begin(); @@ -620,31 +623,27 @@ URI::URI(string U) for (; I < U.end() && *I != ':' ; I++); string::const_iterator FirstColon = I; - // Determine if this is a host type URI with a leading double // + /* Determine if this is a host type URI with a leading double // + and then search for the first single / */ string::const_iterator SingleSlash = I; if (I + 3 < U.end() && I[1] == '/' && I[2] == '/') - { - // Locate the single / that starts the path - for (; I < U.end(); I++) - { - if (*I == '/' && I[1] == '/') - I += 2; - else - if (*I == '/') - break; - } - if (I > U.end()) - I = U.end(); - SingleSlash = I; - } + SingleSlash += 3; + for (; SingleSlash < U.end() && *SingleSlash != '/'; SingleSlash++); + if (SingleSlash > U.end()) + SingleSlash = U.end(); // We can now write the access and path specifiers Access = string(U,0,FirstColon - U.begin()); if (SingleSlash != U.end()) - Path = string(U,SingleSlash - U.begin() + 1); - + Path = string(U,SingleSlash - U.begin()); + if (Path.empty() == true) + Path = "/"; + // Now we attempt to locate a user:pass@host fragment - FirstColon += 3; + if (FirstColon[1] == '/' && FirstColon[2] == '/') + FirstColon += 3; + else + FirstColon += 1; if (FirstColon >= U.end()) return; @@ -693,6 +692,7 @@ URI::operator string() string Res = Access + ':'; if (Host.empty() == false) { + Res += "//"; if (User.empty() == false) { Res += "//" + User; @@ -701,10 +701,21 @@ URI::operator string() Res += "@"; } Res += Host; + if (Port != 0) + { + char S[30]; + sprintf(S,":%u",Port); + Res += S; + } } if (Path.empty() == false) - Res += "/" + Path; + { + if (Path[0] != '/') + Res += "/" + Path; + else + Res += Path; + } return Res; }