Преглед изворни кода

Use C locale instead of C.UTF-8 for protocol strings

The C.UTF-8 locale is not portable, so we need to use C, otherwise
we crash on other systems. We can use std::locale::classic() for
that, which might also be a bit cheaper than using locale("C").
Julian Andres Klode пре 10 година
родитељ
комит
0fb16c3e67
4 измењених фајлова са 6 додато и 6 уклоњено
  1. 1 1
      apt-pkg/acquire-item.cc
  2. 1 1
      apt-pkg/acquire.cc
  3. 2 2
      apt-pkg/contrib/strutl.cc
  4. 2 2
      apt-pkg/install-progress.cc

+ 1 - 1
apt-pkg/acquire-item.cc

@@ -2047,7 +2047,7 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile)	/*{{{*/
    HashStringList ServerHashes;
    unsigned long long ServerSize = 0;
 
-   auto const &posix = std::locale("C.UTF-8");
+   auto const &posix = std::locale::classic();
    for (char const * const * type = HashString::SupportedHashes(); *type != NULL; ++type)
    {
       std::string tagname = *type;

+ 1 - 1
apt-pkg/acquire.cc

@@ -1259,7 +1259,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
 
       // build the status str
       std::ostringstream str;
-      str.imbue(std::locale("C.UTF-8"));
+      str.imbue(std::locale::classic());
       str.precision(4);
       str << "dlstatus" << ':' << std::fixed << i << ':' << Percent << ':' << msg << '\n';
       auto const dlstatus = str.str();

+ 2 - 2
apt-pkg/contrib/strutl.cc

@@ -759,7 +759,7 @@ string TimeRFC1123(time_t Date, bool const NumericTimezone)
    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);
    APT::StringView const fmt("%a, %d %b %Y %H:%M:%S");
@@ -946,7 +946,7 @@ 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("C.UTF-8");
+   auto const &posix = std::locale::classic();
    ss.imbue(posix);
    ss >> weekday;
    // we only superficially check weekday, mostly to avoid accepting localized

+ 2 - 2
apt-pkg/install-progress.cc

@@ -84,7 +84,7 @@ static std::string GetProgressFdString(char const * const status,
 {
    float const progress{Done / static_cast<float>(Total) * 100};
    std::ostringstream str;
-   str.imbue(std::locale("C.UTF-8"));
+   str.imbue(std::locale::classic());
    str.precision(4);
    str << status << ':' << pkg << ':' << std::fixed << progress << ':' << msg << '\n';
    return str.str();
@@ -165,7 +165,7 @@ static std::string GetProgressDeb822String(char const * const status,
 {
    float const progress{Done / static_cast<float>(Total) * 100};
    std::ostringstream str;
-   str.imbue(std::locale("C.UTF-8"));
+   str.imbue(std::locale::classic());
    str.precision(4);
    str << "Status: " << status << '\n';
    if (pkg != nullptr)