197403Sobrien// std::messages implementation details, GNU version -*- C++ -*-
297403Sobrien
3169691Skan// Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
497403Sobrien//
597403Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
697403Sobrien// software; you can redistribute it and/or modify it under the
797403Sobrien// terms of the GNU General Public License as published by the
897403Sobrien// Free Software Foundation; either version 2, or (at your option)
997403Sobrien// any later version.
1097403Sobrien
1197403Sobrien// This library is distributed in the hope that it will be useful,
1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1497403Sobrien// GNU General Public License for more details.
1597403Sobrien
1697403Sobrien// You should have received a copy of the GNU General Public License along
1797403Sobrien// with this library; see the file COPYING.  If not, write to the Free
18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
1997403Sobrien// USA.
2097403Sobrien
2197403Sobrien// As a special exception, you may use this file as part of a free software
2297403Sobrien// library without restriction.  Specifically, if other files instantiate
2397403Sobrien// templates or use macros or inline functions from this file, or you compile
2497403Sobrien// this file and link it with other files to produce an executable, this
2597403Sobrien// file does not by itself cause the resulting executable to be covered by
2697403Sobrien// the GNU General Public License.  This exception does not however
2797403Sobrien// invalidate any other reasons why the executable file might be covered by
2897403Sobrien// the GNU General Public License.
2997403Sobrien
3097403Sobrien//
3197403Sobrien// ISO C++ 14882: 22.2.7.1.2  messages virtual functions
3297403Sobrien//
3397403Sobrien
3497403Sobrien// Written by Benjamin Kosnik <bkoz@redhat.com>
3597403Sobrien
3697403Sobrien#include <locale>
37117397Skan#include <bits/c++locale_internal.h>
3897403Sobrien
39169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
40169691Skan
4197403Sobrien  // Specializations.
4297403Sobrien  template<>
4397403Sobrien    string
4497403Sobrien    messages<char>::do_get(catalog, int, int, const string& __dfault) const
4597403Sobrien    {
4697403Sobrien#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
4797403Sobrien      __c_locale __old = __uselocale(_M_c_locale_messages);
4897403Sobrien      const char* __msg = const_cast<const char*>(gettext(__dfault.c_str()));
4997403Sobrien      __uselocale(__old);
5097403Sobrien      return string(__msg);
5197403Sobrien#else
52102782Skan      char* __old = strdup(setlocale(LC_ALL, NULL));
53102782Skan      setlocale(LC_ALL, _M_name_messages);
5497403Sobrien      const char* __msg = gettext(__dfault.c_str());
5597403Sobrien      setlocale(LC_ALL, __old);
56102782Skan      free(__old);
5797403Sobrien      return string(__msg);
5897403Sobrien#endif
5997403Sobrien    }
60103447Skan
61132720Skan#ifdef _GLIBCXX_USE_WCHAR_T
62103447Skan  template<>
63103447Skan    wstring
64103447Skan    messages<wchar_t>::do_get(catalog, int, int, const wstring& __dfault) const
65103447Skan    {
66103447Skan# if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
67103447Skan      __c_locale __old = __uselocale(_M_c_locale_messages);
68103447Skan      char* __msg = gettext(_M_convert_to_char(__dfault));
69103447Skan      __uselocale(__old);
70103447Skan      return _M_convert_from_char(__msg);
71103447Skan# else
72103447Skan      char* __old = strdup(setlocale(LC_ALL, NULL));
73103447Skan      setlocale(LC_ALL, _M_name_messages);
74103447Skan      char* __msg = gettext(_M_convert_to_char(__dfault));
75103447Skan      setlocale(LC_ALL, __old);
76103447Skan      free(__old);
77103447Skan      return _M_convert_from_char(__msg);
78103447Skan# endif
79103447Skan    }
80103447Skan#endif
81169691Skan
82169691Skan_GLIBCXX_END_NAMESPACE
83