Author: mlandres Date: Wed Nov 14 14:26:04 2007 New Revision: 7807 URL: http://svn.opensuse.org/viewcvs/zypp?rev=7807&view=rev Log: Output date strings in UTF-8. Modified: trunk/libzypp/package/libzypp.changes trunk/libzypp/zypp/Date.cc Modified: trunk/libzypp/package/libzypp.changes URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/package/libzypp.changes?rev=7807&r1=7806&r2=7807&view=diff ============================================================================== --- trunk/libzypp/package/libzypp.changes (original) +++ trunk/libzypp/package/libzypp.changes Wed Nov 14 14:26:04 2007 @@ -1,9 +1,15 @@ ------------------------------------------------------------------- +Wed Nov 14 14:23:23 CET 2007 - ma@suse.de + +- Output date strings in UTF-8. (#339423) +- revision 7807 + +------------------------------------------------------------------- Tue Nov 13 13:40:03 CET 2007 - schubi@suse.de - fixes for new gcc - version 4.1.3 -- r7788 +- r7788 ------------------------------------------------------------------- Mon Nov 5 15:22:33 CET 2007 - ma@suse.de Modified: trunk/libzypp/zypp/Date.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Date.cc?rev=7807&r1=7806&r2=7807&view=diff ============================================================================== --- trunk/libzypp/zypp/Date.cc (original) +++ trunk/libzypp/zypp/Date.cc Wed Nov 14 14:26:04 2007 @@ -38,8 +38,56 @@ std::string Date::form( const std::string & format_r ) const { static char buf[1024]; + + static std::string lastLocale; + static std::string needLocale; + const char * tmp = ::setlocale( LC_TIME, NULL ); + std::string thisLocale( tmp ? tmp : "" ); + + if ( thisLocale != lastLocale ) + { + // locale changes since last call. compute new utf-8 locale + if ( thisLocale.find( "UTF-8" ) != std::string::npos + || thisLocale.find( "utf-8" ) != std::string::npos + || thisLocale == "POSIX" + || thisLocale == "C" + || thisLocale == "" ) + { + // is UTF-8 or C or POSIX + needLocale = thisLocale; + } + else + { + // language[_territory][.codeset][@modifier] + // add/exchange codeset with UTF-8 + needLocale = ".UTF-8"; + std::string::size_type loc = thisLocale.find_first_of( ".@" ); + if ( loc != std::string::npos ) + { + // prepend language[_territory] + needLocale = thisLocale.substr( 0, loc ) + needLocale; + loc = thisLocale.find_last_of( "@" ); + if ( loc != std::string::npos ) + { + // append [@modifier] + needLocale += thisLocale.substr( loc ); + } + } + else + { + // append ".UTF-8" + needLocale = thisLocale + needLocale; + } + } + lastLocale = thisLocale; + } + + if ( needLocale != lastLocale ) + ::setlocale( LC_TIME, needLocale.c_str() ); if ( ! strftime( buf, 1024, format_r.c_str(), localtime( &_date ) ) ) - return std::string(); + *buf = '\0'; + if ( needLocale != lastLocale ) + ::setlocale( LC_TIME, lastLocale.c_str() ); return buf; } -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org