Author: mlandres Date: Wed Oct 22 13:03:58 2008 New Revision: 11440 URL: http://svn.opensuse.org/viewcvs/zypp?rev=11440&view=rev Log: - Add Locale:: bestMatch to find the best match within a set of available Locales. Modified: trunk/libzypp/zypp/Locale.cc trunk/libzypp/zypp/Locale.h Modified: trunk/libzypp/zypp/Locale.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Locale.cc?rev=11440&r1=11439&r2=11440&view=diff ============================================================================== --- trunk/libzypp/zypp/Locale.cc (original) +++ trunk/libzypp/zypp/Locale.cc Wed Oct 22 13:03:58 2008 @@ -221,6 +221,21 @@ // Locale Locale::fallback() const { return _pimpl->fallback(); } + + Locale Locale::bestMatch( const LocaleSet & avLocales_r, const Locale & requested_r ) + { + if ( ! avLocales_r.empty() ) + { + for ( Locale check( requested_r ); check != noCode; check = check.fallback() ) + { + if ( avLocales_r.find( check ) != avLocales_r.end() ) + return check; + } + } + return noCode; + } + + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// Modified: trunk/libzypp/zypp/Locale.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Locale.h?rev=11440&r1=11439&r2=11440&view=diff ============================================================================== --- trunk/libzypp/zypp/Locale.h (original) +++ trunk/libzypp/zypp/Locale.h Wed Oct 22 13:03:58 2008 @@ -25,6 +25,9 @@ namespace zypp { ///////////////////////////////////////////////////////////////// + class Locale; + typedef std::tr1::unordered_set<Locale> LocaleSet; + /////////////////////////////////////////////////////////////////// // // CLASS NAME : Locale @@ -83,6 +86,15 @@ /** Return a fallback locale for this locale, when giving up, returns empty Locale() */ Locale fallback() const; + public: + + /** Return the best match for \ref Locale \c requested_r within the available \c avLocales_r. + * + * If neither \c requested_r nor any of it's \ref fallback locales are available, + * \ref Locale::noCode is returned. + */ + static Locale bestMatch( const LocaleSet & avLocales_r, const Locale & requested_r ); + private: /** Pointer to implementation */ RW_pointer<Impl> _pimpl; @@ -122,10 +134,6 @@ } //@} - /////////////////////////////////////////////////////////////////// - - typedef std::tr1::unordered_set<Locale> LocaleSet; - ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org