1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/LocaleGuard.h
11 #ifndef ZYPP_BASE_LOCALEGUARD_H
12 #define ZYPP_BASE_LOCALEGUARD_H
17 #include "zypp/base/Easy.h"
19 ///////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////
23 /// \class LocaleGuard
24 /// \brief Temorarily change a locale category value
26 ///////////////////////////////////////////////////////////////////
29 NON_COPYABLE(LocaleGuard);
30 NON_MOVABLE(LocaleGuard);
33 /** Ctor saving the current locale category value. */
34 LocaleGuard( int category_r, const std::string & value_r = "C" )
37 const char * ovalue = ::setlocale( category_r, nullptr );
38 if ( ovalue && ovalue != value_r )
40 _category = category_r;
42 ::setlocale( _category, value_r.c_str() );
46 /** Dtor asserts the saved locale category value is restored. */
50 /** immediately restore the saved locale category value. */
53 if ( _category != -1 )
55 ::setlocale( _category, _value.c_str() );
61 int _category; ///< saved category or -1 if no restore needed
62 std::string _value; ///< saved category value
65 ///////////////////////////////////////////////////////////////////
66 #endif // ZYPP_BASE_LOCALEGUARD_H