c++locale.h

00001 // Wrapper for underlying C-language localization -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00019 // USA. 00020 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 // 00031 // ISO C++ 14882: 22.8 Standard locale categories. 00032 // 00033 00034 // Written by Benjamin Kosnik <bkoz@redhat.com> 00035 00036 #include <clocale> 00037 #include <langinfo.h> // For codecvt 00038 #include <iconv.h> // For codecvt using iconv, iconv_t 00039 #include <libintl.h> // For messages 00040 00041 #define _GLIBCPP_C_LOCALE_GNU 1 00042 00043 #define _GLIBCPP_NUM_CATEGORIES 6 00044 00045 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) 00046 namespace __gnu_cxx 00047 { 00048 extern "C" __typeof(uselocale) __uselocale; 00049 } 00050 #endif 00051 00052 namespace std 00053 { 00054 typedef __locale_t __c_locale; 00055 00056 template<typename _Tv> 00057 int 00058 __convert_from_v(char* __out, const int __size, const char* __fmt, 00059 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) 00060 _Tv __v, const __c_locale& __cloc, int __prec = -1) 00061 { 00062 __c_locale __old = __gnu_cxx::__uselocale(__cloc); 00063 #else 00064 _Tv __v, const __c_locale&, int __prec = -1) 00065 { 00066 char* __old = setlocale(LC_ALL, NULL); 00067 char* __sav = static_cast<char*>(malloc(strlen(__old) + 1)); 00068 if (__sav) 00069 strcpy(__sav, __old); 00070 setlocale(LC_ALL, "C"); 00071 #endif 00072 00073 int __ret; 00074 #ifdef _GLIBCPP_USE_C99 00075 if (__prec >= 0) 00076 __ret = snprintf(__out, __size, __fmt, __prec, __v); 00077 else 00078 __ret = snprintf(__out, __size, __fmt, __v); 00079 #else 00080 if (__prec >= 0) 00081 __ret = sprintf(__out, __fmt, __prec, __v); 00082 else 00083 __ret = sprintf(__out, __fmt, __v); 00084 #endif 00085 00086 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) 00087 __gnu_cxx::__uselocale(__old); 00088 #else 00089 setlocale(LC_ALL, __sav); 00090 free(__sav); 00091 #endif 00092 return __ret; 00093 } 00094 }

Generated on Wed Sep 29 13:54:47 2004 for libstdc++-v3 Source by doxygen 1.3.7