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 const Locale Locale::noCode;
114 ///////////////////////////////////////////////////////////////////
116 // METHOD NAME : Locale::Locale
117 // METHOD TYPE : Ctor
120 : _pimpl( Impl::nullimpl() )
123 ///////////////////////////////////////////////////////////////////
125 // METHOD NAME : Locale::Locale
126 // METHOD TYPE : Ctor
128 Locale::Locale( const std::string & code_r )
129 : _pimpl( new Impl( code_r ) )
132 ///////////////////////////////////////////////////////////////////
134 // METHOD NAME : Locale::Locale
135 // METHOD TYPE : Ctor
137 Locale::Locale( const LanguageCode & language_r,
138 const CountryCode & country_r )
139 : _pimpl( new Impl( language_r, country_r ) )
142 ///////////////////////////////////////////////////////////////////
144 // METHOD NAME : Locale::~Locale
145 // METHOD TYPE : Dtor
150 ///////////////////////////////////////////////////////////////////
152 // METHOD NAME : Locale::
155 const LanguageCode & Locale::language() const
156 { return _pimpl->language(); }
158 ///////////////////////////////////////////////////////////////////
160 // METHOD NAME : Locale::
163 const CountryCode & Locale::country() const
164 { return _pimpl->country(); }
166 ///////////////////////////////////////////////////////////////////
168 // METHOD NAME : Locale::
171 std::string Locale::code() const
172 { return _pimpl->code(); }
174 ///////////////////////////////////////////////////////////////////
176 // METHOD NAME : Locale::
179 std::string Locale::name() const
180 { return _pimpl->name(); }
182 /////////////////////////////////////////////////////////////////
184 ///////////////////////////////////////////////////////////////////