c++locale.h

00001 // Wrapper for underlying C-language localization -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004 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 #ifndef _C_LOCALE_H 00037 #define _C_LOCALE_H 1 00038 00039 #pragma GCC system_header 00040 00041 #include <cstring> // get std::strlen 00042 #include <cstdio> // get std::snprintf or std::sprintf 00043 #include <clocale> 00044 #include <langinfo.h> // For codecvt 00045 #include <iconv.h> // For codecvt using iconv, iconv_t 00046 #include <libintl.h> // For messages 00047 00048 #define _GLIBCXX_C_LOCALE_GNU 1 00049 00050 #define _GLIBCXX_NUM_CATEGORIES 6 00051 00052 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) 00053 namespace __gnu_cxx 00054 { 00055 extern "C" __typeof(uselocale) __uselocale; 00056 } 00057 #endif 00058 00059 namespace std 00060 { 00061 typedef __locale_t __c_locale; 00062 00063 // Convert numeric value of type _Tv to string and return length of 00064 // string. If snprintf is available use it, otherwise fall back to 00065 // the unsafe sprintf which, in general, can be dangerous and should 00066 // be avoided. 00067 template<typename _Tv> 00068 int 00069 __convert_from_v(char* __out, const int __size, const char* __fmt, 00070 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) 00071 _Tv __v, const __c_locale& __cloc, int __prec = -1) 00072 { 00073 __c_locale __old = __gnu_cxx::__uselocale(__cloc); 00074 #else 00075 _Tv __v, const __c_locale&, int __prec = -1) 00076 { 00077 char* __old = std::setlocale(LC_ALL, NULL); 00078 char* __sav = new char[std::strlen(__old) + 1]; 00079 std::strcpy(__sav, __old); 00080 std::setlocale(LC_ALL, "C"); 00081 #endif 00082 00083 int __ret; 00084 #ifdef _GLIBCXX_USE_C99 00085 if (__prec >= 0) 00086 __ret = std::snprintf(__out, __size, __fmt, __prec, __v); 00087 else 00088 __ret = std::snprintf(__out, __size, __fmt, __v); 00089 #else 00090 if (__prec >= 0) 00091 __ret = std::sprintf(__out, __fmt, __prec, __v); 00092 else 00093 __ret = std::sprintf(__out, __fmt, __v); 00094 #endif 00095 00096 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) 00097 __gnu_cxx::__uselocale(__old); 00098 #else 00099 std::setlocale(LC_ALL, __sav); 00100 delete [] __sav; 00101 #endif 00102 return __ret; 00103 } 00104 } 00105 00106 #endif

Generated on Wed Jun 9 11:18:16 2004 for libstdc++-v3 Source by doxygen 1.3.7