X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/1d742e01470bba27715a8191c50adde4b39c2f19..d453c9a7ef236b4906b80648ae916a69ae780399:/apt-pkg/contrib/strutl.cc diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 84fc14bb1..cf8feb970 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -749,15 +750,26 @@ int StringToBool(const string &Text,int Default) /* This converts a time_t into a string time representation that is year 2000 complient and timezone neutral */ string TimeRFC1123(time_t Date) +{ + return TimeRFC1123(Date, false); +} +string TimeRFC1123(time_t Date, bool const NumericTimezone) { struct tm Conv; if (gmtime_r(&Date, &Conv) == NULL) return ""; - auto const posix = std::locale("C.UTF-8"); + auto const posix = std::locale::classic(); std::ostringstream datestr; datestr.imbue(posix); - datestr << std::put_time(&Conv, "%a, %d %b %Y %H:%M:%S GMT"); + APT::StringView const fmt("%a, %d %b %Y %H:%M:%S"); + std::use_facet>(posix).put( + std::ostreambuf_iterator(datestr), + datestr, ' ', &Conv, fmt.data(), fmt.data() + fmt.size()); + if (NumericTimezone) + datestr << " +0000"; + else + datestr << " GMT"; return datestr.str(); } /*}}}*/ @@ -934,6 +946,8 @@ bool RFC1123StrToTime(const char* const str,time_t &time) signed int year = 0; // yes, Y23K problem – we gonna worry then… std::string weekday, month, datespec, timespec, zone; std::istringstream ss(str); + auto const &posix = std::locale::classic(); + ss.imbue(posix); ss >> weekday; // we only superficially check weekday, mostly to avoid accepting localized // weekdays here and take only its length to decide which datetime format we @@ -1157,10 +1171,11 @@ bool Base256ToNum(const char *Str,unsigned long long &Res,unsigned int Len) tar files */ bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len) { - unsigned long long Num; + unsigned long long Num = 0; bool rc; rc = Base256ToNum(Str, Num, Len); + // rudimentary check for overflow (Res = ulong, Num = ulonglong) Res = Num; if (Res != Num) return false; @@ -1626,13 +1641,15 @@ void URI::CopyFrom(const string &U) I = FirstColon + 1; if (I > SingleSlash) I = SingleSlash; - for (; I < SingleSlash && *I != ':'; ++I); - string::const_iterator SecondColon = I; - - // Search for the @ after the colon - for (; I < SingleSlash && *I != '@'; ++I); - string::const_iterator At = I; - + + // Search for the @ separating user:pass from host + auto const RevAt = std::find( + std::string::const_reverse_iterator(SingleSlash), + std::string::const_reverse_iterator(I), '@'); + string::const_iterator const At = RevAt.base() == I ? SingleSlash : std::prev(RevAt.base()); + // and then look for the colon between user and pass + string::const_iterator const SecondColon = std::find(I, At, ':'); + // Now write the host and user/pass if (At == SingleSlash) {