1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Locale.cc
13 //#include "zypp/base/Logger.h"
15 #include "zypp/Locale.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
23 ///////////////////////////////////////////////////////////////////
25 // CLASS NAME : Locale::Impl
27 /** Locale implementation. */
33 Impl( const std::string & code_r )
36 std::string::size_type sep = code_r.find_first_of( "@." );
37 if ( sep == std::string::npos ) {
40 t = code_r.substr( 0, sep );
44 if ( sep == std::string::npos ) {
45 _language = LanguageCode( t );
47 _language = LanguageCode( t.substr( 0, sep ) );
48 _country = CountryCode( t.substr( sep+1 ) );
52 Impl( const LanguageCode & language_r,
53 const CountryCode & country_r )
54 : _language( language_r )
55 , _country( country_r )
58 const LanguageCode & language() const
61 const CountryCode & country() const
64 std::string code() const
66 std::string ret( _language.code() );
67 if ( _country.hasCode() )
68 ret += "_" + _country.code();
72 std::string name() const
74 std::string ret( _language.name() );
75 if ( _country.hasCode() )
76 ret += " (" + _country.name() + ")";
82 LanguageCode _language;
86 /** Offer default Impl. */
87 static shared_ptr<Impl> nullimpl()
88 { if ( ! _nullimpl ) _nullimpl.reset( new Impl ); return _nullimpl; }
92 static shared_ptr<Impl> _nullimpl;
94 ///////////////////////////////////////////////////////////////////
96 shared_ptr<Locale::Impl> Locale::Impl::_nullimpl;
98 ///////////////////////////////////////////////////////////////////
100 /** \relates Locale::Impl Stream output */
101 inline std::ostream & operator<<( std::ostream & str, const Locale::Impl & obj )
103 return str << "Locale::Impl";
106 ///////////////////////////////////////////////////////////////////
108 // CLASS NAME : Locale
110 ///////////////////////////////////////////////////////////////////
112 #warning NO STATIC VARIABLES
113 // const Locale Locale::noCode;
115 ///////////////////////////////////////////////////////////////////
117 // METHOD NAME : Locale::Locale
118 // METHOD TYPE : Ctor
121 : _pimpl( Impl::nullimpl() )
124 ///////////////////////////////////////////////////////////////////
126 // METHOD NAME : Locale::Locale
127 // METHOD TYPE : Ctor
129 Locale::Locale( const std::string & code_r )
130 : _pimpl( new Impl( code_r ) )
133 ///////////////////////////////////////////////////////////////////
135 // METHOD NAME : Locale::Locale
136 // METHOD TYPE : Ctor
138 Locale::Locale( const LanguageCode & language_r,
139 const CountryCode & country_r )
140 : _pimpl( new Impl( language_r, country_r ) )
143 ///////////////////////////////////////////////////////////////////
145 // METHOD NAME : Locale::~Locale
146 // METHOD TYPE : Dtor
151 ///////////////////////////////////////////////////////////////////
153 // METHOD NAME : Locale::
156 const LanguageCode & Locale::language() const
157 { return _pimpl->language(); }
159 ///////////////////////////////////////////////////////////////////
161 // METHOD NAME : Locale::
164 const CountryCode & Locale::country() const
165 { return _pimpl->country(); }
167 ///////////////////////////////////////////////////////////////////
169 // METHOD NAME : Locale::
172 std::string Locale::code() const
173 { return _pimpl->code(); }
175 ///////////////////////////////////////////////////////////////////
177 // METHOD NAME : Locale::
180 std::string Locale::name() const
181 { return _pimpl->name(); }
183 /////////////////////////////////////////////////////////////////
185 ///////////////////////////////////////////////////////////////////