removed static variable, which prevents applications linking to libzypp
[platform/upstream/libzypp.git] / zypp / Locale.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/Locale.cc
10  *
11 */
12 #include <iostream>
13 //#include "zypp/base/Logger.h"
14
15 #include "zypp/Locale.h"
16
17 using std::endl;
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22
23   ///////////////////////////////////////////////////////////////////
24   //
25   //    CLASS NAME : Locale::Impl
26   //
27   /** Locale implementation. */
28   struct Locale::Impl
29   {
30     Impl()
31     {}
32
33     Impl( const std::string & code_r )
34     {
35       std::string t;
36       std::string::size_type sep = code_r.find_first_of( "@." );
37       if ( sep == std::string::npos ) {
38         t = code_r;
39       } else {
40         t = code_r.substr( 0, sep );
41       }
42
43       sep = t.find( '_' );
44       if ( sep == std::string::npos ) {
45         _language = LanguageCode( t );
46       } else {
47         _language = LanguageCode( t.substr( 0, sep ) );
48         _country = CountryCode( t.substr( sep+1 ) );
49       }
50     }
51
52     Impl( const LanguageCode & language_r,
53           const CountryCode & country_r )
54     : _language( language_r )
55     , _country( country_r )
56     {}
57
58     const LanguageCode & language() const
59     { return _language; }
60
61     const CountryCode & country() const
62     { return _country; }
63
64     std::string code() const
65     {
66       std::string ret( _language.code() );
67       if ( _country.hasCode() )
68         ret += "_" + _country.code();
69       return ret;
70     }
71
72     std::string name() const
73     {
74       std::string ret( _language.name() );
75       if ( _country.hasCode() )
76         ret += " (" + _country.name() + ")";
77       return ret;
78     }
79
80   private:
81
82     LanguageCode _language;
83     CountryCode _country;
84
85   public:
86     /** Offer default Impl. */
87     static shared_ptr<Impl> nullimpl()
88     { if ( ! _nullimpl ) _nullimpl.reset( new Impl ); return _nullimpl; }
89
90   private:
91     /** Default Impl. */
92     static shared_ptr<Impl> _nullimpl;
93   };
94   ///////////////////////////////////////////////////////////////////
95
96   shared_ptr<Locale::Impl> Locale::Impl::_nullimpl;
97
98   ///////////////////////////////////////////////////////////////////
99
100   /** \relates Locale::Impl Stream output */
101   inline std::ostream & operator<<( std::ostream & str, const Locale::Impl & obj )
102   {
103     return str << "Locale::Impl";
104   }
105
106   ///////////////////////////////////////////////////////////////////
107   //
108   //    CLASS NAME : Locale
109   //
110   ///////////////////////////////////////////////////////////////////
111
112 #warning NO STATIC VARIABLES
113 //  const Locale Locale::noCode;
114
115   ///////////////////////////////////////////////////////////////////
116   //
117   //    METHOD NAME : Locale::Locale
118   //    METHOD TYPE : Ctor
119   //
120   Locale::Locale()
121   : _pimpl( Impl::nullimpl() )
122   {}
123
124   ///////////////////////////////////////////////////////////////////
125   //
126   //    METHOD NAME : Locale::Locale
127   //    METHOD TYPE : Ctor
128   //
129   Locale::Locale( const std::string & code_r )
130   : _pimpl( new Impl( code_r ) )
131   {}
132
133   ///////////////////////////////////////////////////////////////////
134   //
135   //    METHOD NAME : Locale::Locale
136   //    METHOD TYPE : Ctor
137   //
138   Locale::Locale( const LanguageCode & language_r,
139                   const CountryCode & country_r )
140   : _pimpl( new Impl( language_r, country_r ) )
141   {}
142
143   ///////////////////////////////////////////////////////////////////
144   //
145   //    METHOD NAME : Locale::~Locale
146   //    METHOD TYPE : Dtor
147   //
148   Locale::~Locale()
149   {}
150
151   ///////////////////////////////////////////////////////////////////
152   //
153   //    METHOD NAME : Locale::
154   //    METHOD TYPE :
155   //
156   const LanguageCode & Locale::language() const
157   { return _pimpl->language(); }
158
159   ///////////////////////////////////////////////////////////////////
160   //
161   //    METHOD NAME : Locale::
162   //    METHOD TYPE :
163   //
164   const CountryCode & Locale::country() const
165   { return _pimpl->country(); }
166
167   ///////////////////////////////////////////////////////////////////
168   //
169   //    METHOD NAME : Locale::
170   //    METHOD TYPE :
171   //
172   std::string Locale::code() const
173   { return _pimpl->code(); }
174
175   ///////////////////////////////////////////////////////////////////
176   //
177   //    METHOD NAME : Locale::
178   //    METHOD TYPE :
179   //
180   std::string Locale::name() const
181   { return _pimpl->name(); }
182
183   /////////////////////////////////////////////////////////////////
184 } // namespace zypp
185 ///////////////////////////////////////////////////////////////////