messages_members.cc revision 117397
12702Swollman// std::messages implementation details, GNU version -*- C++ -*-
22702Swollman
342997Swollman// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
42702Swollman//
52702Swollman// This file is part of the GNU ISO C++ Library.  This library is free
62702Swollman// software; you can redistribute it and/or modify it under the
730829Scharnier// terms of the GNU General Public License as published by the
830829Scharnier// Free Software Foundation; either version 2, or (at your option)
943774Swollman// any later version.
1030829Scharnier
1130829Scharnier// This library is distributed in the hope that it will be useful,
122702Swollman// but WITHOUT ANY WARRANTY; without even the implied warranty of
132702Swollman// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1430829Scharnier// GNU General Public License for more details.
1530829Scharnier
169937Swollman// You should have received a copy of the GNU General Public License along
179937Swollman// with this library; see the file COPYING.  If not, write to the Free
189937Swollman// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
192702Swollman// USA.
2017214Swollman
2117214Swollman// As a special exception, you may use this file as part of a free software
2217214Swollman// library without restriction.  Specifically, if other files instantiate
2317214Swollman// templates or use macros or inline functions from this file, or you compile
2417214Swollman// this file and link it with other files to produce an executable, this
2517214Swollman// file does not by itself cause the resulting executable to be covered by
2617214Swollman// the GNU General Public License.  This exception does not however
2717214Swollman// invalidate any other reasons why the executable file might be covered by
2817214Swollman// the GNU General Public License.
2917214Swollman
3017214Swollman//
3117214Swollman// ISO C++ 14882: 22.2.7.1.2  messages virtual functions
3217214Swollman//
332702Swollman
342702Swollman// Written by Benjamin Kosnik <bkoz@redhat.com>
352702Swollman
362702Swollman#include <locale>
372702Swollman#include <bits/c++locale_internal.h>
382702Swollman
392702Swollmannamespace std
402702Swollman{
412702Swollman  // Specializations.
422702Swollman  template<>
432702Swollman    string
442702Swollman    messages<char>::do_get(catalog, int, int, const string& __dfault) const
452702Swollman    {
462702Swollman#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
472702Swollman      __c_locale __old = __uselocale(_M_c_locale_messages);
482702Swollman      const char* __msg = const_cast<const char*>(gettext(__dfault.c_str()));
492702Swollman      __uselocale(__old);
502702Swollman      return string(__msg);
519937Swollman#else
529937Swollman      char* __old = strdup(setlocale(LC_ALL, NULL));
532702Swollman      setlocale(LC_ALL, _M_name_messages);
542702Swollman      const char* __msg = gettext(__dfault.c_str());
552702Swollman      setlocale(LC_ALL, __old);
562702Swollman      free(__old);
572702Swollman      return string(__msg);
582702Swollman#endif
592702Swollman    }
602702Swollman
612702Swollman#ifdef _GLIBCPP_USE_WCHAR_T
622702Swollman  template<>
632702Swollman    wstring
642702Swollman    messages<wchar_t>::do_get(catalog, int, int, const wstring& __dfault) const
652702Swollman    {
662702Swollman# if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
672702Swollman      __c_locale __old = __uselocale(_M_c_locale_messages);
682702Swollman      char* __msg = gettext(_M_convert_to_char(__dfault));
692702Swollman      __uselocale(__old);
702702Swollman      return _M_convert_from_char(__msg);
712702Swollman# else
722702Swollman      char* __old = strdup(setlocale(LC_ALL, NULL));
732702Swollman      setlocale(LC_ALL, _M_name_messages);
742702Swollman      char* __msg = gettext(_M_convert_to_char(__dfault));
752702Swollman      setlocale(LC_ALL, __old);
762702Swollman      free(__old);
772702Swollman      return _M_convert_from_char(__msg);
782702Swollman# endif
792702Swollman    }
802702Swollman#endif
812702Swollman}
822702Swollman