X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/0db4a45bf91faa06616a90865068ac6c07885edf..d7cf5923a093e89ab5aac0bf8cd1c3042997990c:/apt-pkg/contrib/strutl.cc diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 5312a3f4f..3bbaf5f30 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.39 2001/05/27 05:19:30 jgg Exp $ +// $Id: strutl.cc,v 1.48 2003/07/18 14:15:11 mdz Exp $ /* ###################################################################### String Util - Some useful string functions. @@ -15,10 +15,6 @@ ##################################################################### */ /*}}}*/ // Includes /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/strutl.h" -#endif - #include #include #include @@ -28,14 +24,88 @@ #include #include #include +#include #include #include #include #include +#include + +#include "config.h" using namespace std; /*}}}*/ +// UTF8ToCodeset - Convert some UTF-8 string for some codeset /*{{{*/ +// --------------------------------------------------------------------- +/* This is handy to use before display some information for enduser */ +bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest) +{ + iconv_t cd; + const char *inbuf; + char *inptr, *outbuf; + size_t insize, bufsize; + dest->clear(); + + cd = iconv_open(codeset, "UTF-8"); + if (cd == (iconv_t)(-1)) { + // Something went wrong + if (errno == EINVAL) + _error->Error("conversion from 'UTF-8' to '%s' not available", + codeset); + else + perror("iconv_open"); + + return false; + } + + insize = bufsize = orig.size(); + inbuf = orig.data(); + inptr = (char *)inbuf; + outbuf = new char[bufsize]; + size_t lastError = -1; + + while (insize != 0) + { + char *outptr = outbuf; + size_t outsize = bufsize; + size_t const err = iconv(cd, &inptr, &insize, &outptr, &outsize); + dest->append(outbuf, outptr - outbuf); + if (err == (size_t)(-1)) + { + switch (errno) + { + case EILSEQ: + insize--; + inptr++; + // replace a series of unknown multibytes with a single "?" + if (lastError != insize) { + lastError = insize - 1; + dest->append("?"); + } + break; + case EINVAL: + insize = 0; + break; + case E2BIG: + if (outptr == outbuf) + { + bufsize *= 2; + delete[] outbuf; + outbuf = new char[bufsize]; + } + break; + } + } + } + + delete[] outbuf; + + iconv_close(cd); + + return true; +} + /*}}}*/ // strstrip - Remove white space from the front and back of a string /*{{{*/ // --------------------------------------------------------------------- /* This is handy to use when parsing a file. It also removes \n's left @@ -197,10 +267,10 @@ bool ParseCWord(const char *&String,string &Res) // QuoteString - Convert a string into quoted from /*{{{*/ // --------------------------------------------------------------------- /* */ -string QuoteString(string Str,const char *Bad) +string QuoteString(const string &Str, const char *Bad) { string Res; - for (const char *I = Str.c_str(); *I != 0; I++) + for (string::const_iterator I = Str.begin(); I != Str.end(); I++) { if (strchr(Bad,*I) != 0 || isprint(*I) == 0 || *I <= 0x20 || *I >= 0x7F) @@ -218,12 +288,12 @@ string QuoteString(string Str,const char *Bad) // DeQuoteString - Convert a string from quoted from /*{{{*/ // --------------------------------------------------------------------- /* This undoes QuoteString */ -string DeQuoteString(string Str) +string DeQuoteString(const string &Str) { string Res; - for (const char *I = Str.c_str(); *I != 0; I++) + for (string::const_iterator I = Str.begin(); I != Str.end(); I++) { - if (*I == '%' && I + 2 < Str.c_str() + Str.length()) + if (*I == '%' && I + 2 < Str.end()) { char Tmp[3]; Tmp[0] = I[1]; @@ -262,13 +332,13 @@ string SizeToStr(double Size) { if (ASize < 100 && I != 0) { - sprintf(S,"%.1f%c",ASize,Ext[I]); + sprintf(S,"%'.1f%c",ASize,Ext[I]); break; } if (ASize < 10000) { - sprintf(S,"%.0f%c",ASize,Ext[I]); + sprintf(S,"%'.0f%c",ASize,Ext[I]); break; } ASize /= 1000.0; @@ -289,23 +359,27 @@ string TimeToStr(unsigned long Sec) { if (Sec > 60*60*24) { - sprintf(S,"%lid %lih%lim%lis",Sec/60/60/24,(Sec/60/60) % 24,(Sec/60) % 60,Sec % 60); + //d means days, h means hours, min means minutes, s means seconds + sprintf(S,_("%lid %lih %limin %lis"),Sec/60/60/24,(Sec/60/60) % 24,(Sec/60) % 60,Sec % 60); break; } if (Sec > 60*60) { - sprintf(S,"%lih%lim%lis",Sec/60/60,(Sec/60) % 60,Sec % 60); + //h means hours, min means minutes, s means seconds + sprintf(S,_("%lih %limin %lis"),Sec/60/60,(Sec/60) % 60,Sec % 60); break; } if (Sec > 60) { - sprintf(S,"%lim%lis",Sec/60,Sec % 60); + //min means minutes, s means seconds + sprintf(S,_("%limin %lis"),Sec/60,Sec % 60); break; } - - sprintf(S,"%lis",Sec); + + //s means seconds + sprintf(S,_("%lis"),Sec); break; } @@ -315,7 +389,7 @@ string TimeToStr(unsigned long Sec) // SubstVar - Substitute a string for another string /*{{{*/ // --------------------------------------------------------------------- /* This replaces all occurances of Subst with Contents in Str. */ -string SubstVar(string Str,string Subst,string Contents) +string SubstVar(const string &Str,const string &Subst,const string &Contents) { string::size_type Pos = 0; string::size_type OldPos = 0; @@ -341,26 +415,34 @@ string SubstVar(string Str,const struct SubstVar *Vars) return Str; } /*}}}*/ +// OutputInDepth - return a string with separator multiplied with depth /*{{{*/ +// --------------------------------------------------------------------- +/* Returns a string with the supplied separator depth + 1 times in it */ +std::string OutputInDepth(const unsigned long Depth, const char* Separator) +{ + std::string output = ""; + for(unsigned long d=Depth+1; d > 0; d--) + output.append(Separator); + return output; +} + /*}}}*/ // URItoFileName - Convert the uri into a unique file name /*{{{*/ // --------------------------------------------------------------------- /* This converts a URI into a safe filename. It quotes all unsafe characters and converts / to _ and removes the scheme identifier. The resulting file name should be unique and never occur again for a different file */ -string URItoFileName(string URI) +string URItoFileName(const string &URI) { // Nuke 'sensitive' items ::URI U(URI); - U.User = string(); - U.Password = string(); - U.Access = ""; + U.User.clear(); + U.Password.clear(); + U.Access.clear(); // "\x00-\x20{}|\\\\^\\[\\]<>\"\x7F-\xFF"; - URI = QuoteString(U,"\\|{}[]<>\"^~_=!@#$%^&*"); - char *J = const_cast(URI.c_str()); - for (; *J != 0; J++) - if (*J == '/') - *J = '_'; - return URI; + string NewURI = QuoteString(U,"\\|{}[]<>\"^~_=!@#$%^&*"); + replace(NewURI.begin(),NewURI.end(),'/','_'); + return NewURI; } /*}}}*/ // Base64Encode - Base64 Encoding routine for short strings /*{{{*/ @@ -369,7 +451,7 @@ string URItoFileName(string URI) from wget and then patched and bug fixed. This spec can be found in rfc2045 */ -string Base64Encode(string S) +string Base64Encode(const string &S) { // Conversion table. static char tbl[64] = {'A','B','C','D','E','F','G','H', @@ -387,24 +469,24 @@ string Base64Encode(string S) /* Transform the 3x8 bits to 4x6 bits, as required by base64. */ - for (const char *I = S.c_str(); I < (S.c_str() + S.length()); I += 3) + for (string::const_iterator I = S.begin(); I < S.end(); I += 3) { char Bits[3] = {0,0,0}; Bits[0] = I[0]; - if (I + 1 < S.c_str() + S.length()) + if (I + 1 < S.end()) Bits[1] = I[1]; - if (I + 2 < S.c_str() + S.length()) + if (I + 2 < S.end()) Bits[2] = I[2]; Final += tbl[Bits[0] >> 2]; Final += tbl[((Bits[0] & 3) << 4) + (Bits[1] >> 4)]; - if (I + 1 >= S.c_str() + S.length()) + if (I + 1 >= S.end()) break; Final += tbl[((Bits[1] & 0xf) << 2) + (Bits[2] >> 6)]; - if (I + 2 >= S.c_str() + S.length()) + if (I + 2 >= S.end()) break; Final += tbl[Bits[2] & 0x3f]; @@ -420,9 +502,9 @@ string Base64Encode(string S) return Final; } /*}}}*/ -// stringcmp - Arbitary string compare /*{{{*/ +// stringcmp - Arbitrary string compare /*{{{*/ // --------------------------------------------------------------------- -/* This safely compares two non-null terminated strings of arbitary +/* This safely compares two non-null terminated strings of arbitrary length */ int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd) { @@ -440,8 +522,45 @@ int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd) return -1; return 1; } + +#if __GNUC__ >= 3 +int stringcmp(string::const_iterator A,string::const_iterator AEnd, + const char *B,const char *BEnd) +{ + for (; A != AEnd && B != BEnd; A++, B++) + if (*A != *B) + break; + + if (A == AEnd && B == BEnd) + return 0; + if (A == AEnd) + return 1; + if (B == BEnd) + return -1; + if (*A < *B) + return -1; + return 1; +} +int stringcmp(string::const_iterator A,string::const_iterator AEnd, + string::const_iterator B,string::const_iterator BEnd) +{ + for (; A != AEnd && B != BEnd; A++, B++) + if (*A != *B) + break; + + if (A == AEnd && B == BEnd) + return 0; + if (A == AEnd) + return 1; + if (B == BEnd) + return -1; + if (*A < *B) + return -1; + return 1; +} +#endif /*}}}*/ -// stringcasecmp - Arbitary case insensitive string compare /*{{{*/ +// stringcasecmp - Arbitrary case insensitive string compare /*{{{*/ // --------------------------------------------------------------------- /* */ int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd) @@ -460,31 +579,67 @@ int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd) return -1; return 1; } +#if __GNUC__ >= 3 +int stringcasecmp(string::const_iterator A,string::const_iterator AEnd, + const char *B,const char *BEnd) +{ + for (; A != AEnd && B != BEnd; A++, B++) + if (toupper(*A) != toupper(*B)) + break; + + if (A == AEnd && B == BEnd) + return 0; + if (A == AEnd) + return 1; + if (B == BEnd) + return -1; + if (toupper(*A) < toupper(*B)) + return -1; + return 1; +} +int stringcasecmp(string::const_iterator A,string::const_iterator AEnd, + string::const_iterator B,string::const_iterator BEnd) +{ + for (; A != AEnd && B != BEnd; A++, B++) + if (toupper(*A) != toupper(*B)) + break; + + if (A == AEnd && B == BEnd) + return 0; + if (A == AEnd) + return 1; + if (B == BEnd) + return -1; + if (toupper(*A) < toupper(*B)) + return -1; + return 1; +} +#endif /*}}}*/ // LookupTag - Lookup the value of a tag in a taged string /*{{{*/ // --------------------------------------------------------------------- /* The format is like those used in package files and the method communication system */ -string LookupTag(string Message,const char *Tag,const char *Default) +string LookupTag(const string &Message,const char *Tag,const char *Default) { // Look for a matching tag. int Length = strlen(Tag); - for (const char *I = Message.c_str(); I + Length < Message.c_str() + Message.length(); I++) + for (string::const_iterator I = Message.begin(); I + Length < Message.end(); I++) { // Found the tag if (I[Length] == ':' && stringcasecmp(I,I+Length,Tag) == 0) { // Find the end of line and strip the leading/trailing spaces - const char *J; + string::const_iterator J; I += Length + 1; - for (; isspace(*I) != 0 && *I != 0; I++); - for (J = I; *J != '\n' && *J != 0; J++); + for (; isspace(*I) != 0 && I < Message.end(); I++); + for (J = I; *J != '\n' && J < Message.end(); J++); for (; J > I && isspace(J[-1]) != 0; J--); return string(I,J); } - for (; *I != '\n' && *I != 0; I++); + for (; *I != '\n' && I < Message.end(); I++); } // Failed to find a match @@ -497,7 +652,7 @@ string LookupTag(string Message,const char *Tag,const char *Default) // --------------------------------------------------------------------- /* This inspects the string to see if it is true or if it is false and then returns the result. Several varients on true/false are checked. */ -int StringToBool(string Text,int Default) +int StringToBool(const string &Text,int Default) { char *End; int Res = strtol(Text.c_str(),&End,0); @@ -546,11 +701,24 @@ string TimeRFC1123(time_t Date) // --------------------------------------------------------------------- /* This pulls full messages from the input FD into the message buffer. It assumes that messages will not pause during transit so no - fancy buffering is used. */ + fancy buffering is used. + + In particular: this reads blocks from the input until it believes + that it's run out of input text. Each block is terminated by a + double newline ('\n' followed by '\n'). As noted below, there is a + bug in this code: it assumes that all the blocks have been read if + it doesn't see additional text in the buffer after the last one is + parsed, which will cause it to lose blocks if the last block + coincides with the end of the buffer. + */ bool ReadMessages(int Fd, vector &List) { - char Buffer[4000]; + char Buffer[64000]; char *End = Buffer; + // Represents any left-over from the previous iteration of the + // parse loop. (i.e., if a message is split across the end + // of the buffer, it goes here) + string PartialMessage; while (1) { @@ -577,7 +745,8 @@ bool ReadMessages(int Fd, vector &List) continue; // Pull the message out - string Message(Buffer,0,I-Buffer); + string Message(Buffer,I-Buffer); + PartialMessage += Message; // Fix up the buffer for (; I < End && *I == '\n'; I++); @@ -585,10 +754,32 @@ bool ReadMessages(int Fd, vector &List) memmove(Buffer,I,End-Buffer); I = Buffer; - List.push_back(Message); + List.push_back(PartialMessage); + PartialMessage.clear(); } - if (End == Buffer) - return true; + if (End != Buffer) + { + // If there's text left in the buffer, store it + // in PartialMessage and throw the rest of the buffer + // away. This allows us to handle messages that + // are longer than the static buffer size. + PartialMessage += string(Buffer, End); + End = Buffer; + } + else + { + // BUG ALERT: if a message block happens to end at a + // multiple of 64000 characters, this will cause it to + // terminate early, leading to a badly formed block and + // probably crashing the method. However, this is the only + // way we have to find the end of the message block. I have + // an idea of how to fix this, but it will require changes + // to the protocol (essentially to mark the beginning and + // end of the block). + // + // -- dburrows 2008-04-02 + return true; + } if (WaitFd(Fd) == false) return false; @@ -639,7 +830,11 @@ static int MonthConv(char *Month) Contributed by Roger Beeman , with the help of Mark Baushke and the rest of the Gurus at CISCO. */ -#ifndef __USE_MISC // glib sets this + +/* Turned it into an autoconf check, because GNU is not the only thing which + can provide timegm. -- 2002-09-22, Joel Baker */ + +#ifndef HAVE_TIMEGM // Now with autoconf! static time_t timegm(struct tm *t) { time_t tl, tb; @@ -659,7 +854,7 @@ static time_t timegm(struct tm *t) 'timegm' to convert a struct tm in UTC to a time_t. For some bizzar reason the C library does not provide any such function :< This also handles the weird, but unambiguous FTP time format*/ -bool StrToTime(string Val,time_t &Result) +bool StrToTime(const string &Val,time_t &Result) { struct tm Tm; char Month[10]; @@ -746,7 +941,7 @@ static int HexDigit(int c) // Hex2Num - Convert a long hex number into a buffer /*{{{*/ // --------------------------------------------------------------------- /* The length of the buffer must be exactly 1/2 the length of the string. */ -bool Hex2Num(string Str,unsigned char *Num,unsigned int Length) +bool Hex2Num(const string &Str,unsigned char *Num,unsigned int Length) { if (Str.length() != Length*2) return false; @@ -805,6 +1000,24 @@ bool TokSplitString(char Tok,char *Input,char **List, return true; } /*}}}*/ +// ExplodeString - Split a string up into a vector /*{{{*/ +// --------------------------------------------------------------------- +/* This can be used to split a given string up into a vector, so the + propose is the same as in the method above and this one is a bit slower + also, but the advantage is that we an iteratable vector */ +vector ExplodeString(string const &haystack, char const &split) +{ + string::const_iterator start = haystack.begin(); + string::const_iterator end = start; + vector exploded; + do { + for (; end != haystack.end() && *end != split; ++end); + exploded.push_back(string(start, end)); + start = end + 1; + } while (end != haystack.end() && (++end) != haystack.end()); + return exploded; +} + /*}}}*/ // RegexChoice - Simple regex list/list matcher /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -867,17 +1080,65 @@ unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin, /*}}}*/ // ioprintf - C format string outputter to C++ iostreams /*{{{*/ // --------------------------------------------------------------------- -/* This is used to make the internationalization strinc easier to translate - and to allow reordering of parameters */ +/* This is used to make the internationalization strings easier to translate + and to allow reordering of parameters */ void ioprintf(ostream &out,const char *format,...) { va_list args; va_start(args,format); // sprintf the description - char S[400]; + char S[4096]; + vsnprintf(S,sizeof(S),format,args); + out << S; +} + /*}}}*/ +// strprintf - C format string outputter to C++ strings /*{{{*/ +// --------------------------------------------------------------------- +/* This is used to make the internationalization strings easier to translate + and to allow reordering of parameters */ +void strprintf(string &out,const char *format,...) +{ + va_list args; + va_start(args,format); + + // sprintf the description + char S[4096]; vsnprintf(S,sizeof(S),format,args); - // std::ostream::operator <<(out, (const char *)S); + out = string(S); +} + /*}}}*/ +// safe_snprintf - Safer snprintf /*{{{*/ +// --------------------------------------------------------------------- +/* This is a snprintf that will never (ever) go past 'End' and returns a + pointer to the end of the new string. The returned string is always null + terminated unless Buffer == end. This is a better alterantive to using + consecutive snprintfs. */ +char *safe_snprintf(char *Buffer,char *End,const char *Format,...) +{ + va_list args; + unsigned long Did; + + va_start(args,Format); + + if (End <= Buffer) + return End; + + Did = vsnprintf(Buffer,End - Buffer,Format,args); + if (Did < 0 || Buffer + Did > End) + return End; + return Buffer + Did; +} + /*}}}*/ + +// tolower_ascii - tolower() function that ignores the locale /*{{{*/ +// --------------------------------------------------------------------- +/* */ +int tolower_ascii(int c) +{ + if (c >= 'A' and c <= 'Z') + return c + 32; + return c; } /*}}}*/ @@ -885,18 +1146,18 @@ void ioprintf(ostream &out,const char *format,...) // --------------------------------------------------------------------- /* The domain list is a comma seperate list of domains that are suffix matched against the argument */ -bool CheckDomainList(string Host,string List) +bool CheckDomainList(const string &Host,const string &List) { - const char *Start = List.c_str(); - for (const char *Cur = List.c_str(); *Cur != 0; Cur++) + string::const_iterator Start = List.begin(); + for (string::const_iterator Cur = List.begin(); Cur <= List.end(); Cur++) { - if (*Cur != ',') + if (Cur < List.end() && *Cur != ',') continue; // Match the end of the string.. - if ((Host.size() >= (unsigned)(Cur - List.c_str())) && + if ((Host.size() >= (unsigned)(Cur - Start)) && Cur - Start != 0 && - stringcasecmp(Host.c_str() + Host.length() - (Cur - Start),Host.c_str()+Host.length(),Start,Cur) == 0) + stringcasecmp(Host.end() - (Cur - Start),Host.end(),Start,Cur) == 0) return true; Start = Cur + 1; @@ -908,24 +1169,24 @@ bool CheckDomainList(string Host,string List) // URI::CopyFrom - Copy from an object /*{{{*/ // --------------------------------------------------------------------- /* This parses the URI into all of its components */ -void URI::CopyFrom(string U) +void URI::CopyFrom(const string &U) { - const char *I = U.c_str(); + string::const_iterator I = U.begin(); // Locate the first colon, this separates the scheme - for (; *I != 0 && *I != ':' ; I++); - const char *FirstColon = I; + for (; I < U.end() && *I != ':' ; I++); + string::const_iterator FirstColon = I; /* Determine if this is a host type URI with a leading double // and then search for the first single / */ - const char *SingleSlash = I; - if (I + 3 < U.c_str() + U.length() && I[1] == '/' && I[2] == '/') + string::const_iterator SingleSlash = I; + if (I + 3 < U.end() && I[1] == '/' && I[2] == '/') SingleSlash += 3; /* Find the / indicating the end of the hostname, ignoring /'s in the square brackets */ bool InBracket = false; - for (; SingleSlash < U.c_str() + U.length() && (*SingleSlash != '/' || InBracket == true); SingleSlash++) + for (; SingleSlash < U.end() && (*SingleSlash != '/' || InBracket == true); SingleSlash++) { if (*SingleSlash == '[') InBracket = true; @@ -933,22 +1194,22 @@ void URI::CopyFrom(string U) InBracket = false; } - if (SingleSlash > U.c_str() + U.length()) - SingleSlash = U.c_str() + U.length(); + if (SingleSlash > U.end()) + SingleSlash = U.end(); // We can now write the access and path specifiers - Access = string(U,0,FirstColon - U.c_str()); - if (*SingleSlash != 0) - Path = string(U,SingleSlash - U.c_str()); + Access.assign(U.begin(),FirstColon); + if (SingleSlash != U.end()) + Path.assign(SingleSlash,U.end()); if (Path.empty() == true) Path = "/"; // Now we attempt to locate a user:pass@host fragment - if (FirstColon[1] == '/' && FirstColon[2] == '/') + if (FirstColon + 2 <= U.end() && FirstColon[1] == '/' && FirstColon[2] == '/') FirstColon += 3; else FirstColon += 1; - if (FirstColon >= U.c_str() + U.length()) + if (FirstColon >= U.end()) return; if (FirstColon > SingleSlash) @@ -959,24 +1220,24 @@ void URI::CopyFrom(string U) if (I > SingleSlash) I = SingleSlash; for (; I < SingleSlash && *I != ':'; I++); - const char *SecondColon = I; + string::const_iterator SecondColon = I; // Search for the @ after the colon for (; I < SingleSlash && *I != '@'; I++); - const char *At = I; + string::const_iterator At = I; // Now write the host and user/pass if (At == SingleSlash) { if (FirstColon < SingleSlash) - Host = string(U,FirstColon - U.c_str(),SingleSlash - FirstColon); + Host.assign(FirstColon,SingleSlash); } else { - Host = string(U,At - U.c_str() + 1,SingleSlash - At - 1); - User = string(U,FirstColon - U.c_str(),SecondColon - FirstColon); + Host.assign(At+1,SingleSlash); + User.assign(FirstColon,SecondColon); if (SecondColon < At) - Password = string(U,SecondColon - U.c_str() + 1,At - SecondColon - 1); + Password.assign(SecondColon+1,At); } // Now we parse the RFC 2732 [] hostnames. @@ -1004,7 +1265,7 @@ void URI::CopyFrom(string U) // Tsk, weird. if (InBracket == true) { - Host = string(); + Host.clear(); return; } @@ -1015,7 +1276,7 @@ void URI::CopyFrom(string U) return; Port = atoi(string(Host,Pos+1).c_str()); - Host = string(Host,0,Pos); + Host.assign(Host,0,Pos); } /*}}}*/ // URI::operator string - Convert the URI to a string /*{{{*/ @@ -1070,12 +1331,12 @@ URI::operator string() // URI::SiteOnly - Return the schema and site for the URI /*{{{*/ // --------------------------------------------------------------------- /* */ -string URI::SiteOnly(string URI) +string URI::SiteOnly(const string &URI) { ::URI U(URI); - U.User = string(); - U.Password = string(); - U.Path = string(); + U.User.clear(); + U.Password.clear(); + U.Path.clear(); U.Port = 0; return U; }