1*e4b17023SJohn Marino // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2*e4b17023SJohn Marino // 2006, 2007, 2008, 2009, 2010, 2011 3*e4b17023SJohn Marino // Free Software Foundation, Inc. 4*e4b17023SJohn Marino // 5*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library. This library is free 6*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the 7*e4b17023SJohn Marino // terms of the GNU General Public License as published by the 8*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option) 9*e4b17023SJohn Marino // any later version. 10*e4b17023SJohn Marino 11*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, 12*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*e4b17023SJohn Marino // GNU General Public License for more details. 15*e4b17023SJohn Marino 16*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional 17*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version 18*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation. 19*e4b17023SJohn Marino 20*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and 21*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program; 22*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>. 24*e4b17023SJohn Marino 25*e4b17023SJohn Marino #include <locale> 26*e4b17023SJohn Marino #include <cstdlib> 27*e4b17023SJohn Marino #include <cstring> 28*e4b17023SJohn Marino 29*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 30*e4b17023SJohn Marino { 31*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 32*e4b17023SJohn Marino 33*e4b17023SJohn Marino // Definitions for static const data members of ctype_base. 34*e4b17023SJohn Marino const ctype_base::mask ctype_base::space; 35*e4b17023SJohn Marino const ctype_base::mask ctype_base::print; 36*e4b17023SJohn Marino const ctype_base::mask ctype_base::cntrl; 37*e4b17023SJohn Marino const ctype_base::mask ctype_base::upper; 38*e4b17023SJohn Marino const ctype_base::mask ctype_base::lower; 39*e4b17023SJohn Marino const ctype_base::mask ctype_base::alpha; 40*e4b17023SJohn Marino const ctype_base::mask ctype_base::digit; 41*e4b17023SJohn Marino const ctype_base::mask ctype_base::punct; 42*e4b17023SJohn Marino const ctype_base::mask ctype_base::xdigit; 43*e4b17023SJohn Marino const ctype_base::mask ctype_base::alnum; 44*e4b17023SJohn Marino const ctype_base::mask ctype_base::graph; 45*e4b17023SJohn Marino 46*e4b17023SJohn Marino // Definitions for locale::id of standard facets that are specialized. 47*e4b17023SJohn Marino locale::id ctype<char>::id; 48*e4b17023SJohn Marino 49*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 50*e4b17023SJohn Marino locale::id ctype<wchar_t>::id; 51*e4b17023SJohn Marino #endif 52*e4b17023SJohn Marino 53*e4b17023SJohn Marino const size_t ctype<char>::table_size; 54*e4b17023SJohn Marino ~ctype()55*e4b17023SJohn Marino ctype<char>::~ctype() 56*e4b17023SJohn Marino { 57*e4b17023SJohn Marino _S_destroy_c_locale(_M_c_locale_ctype); 58*e4b17023SJohn Marino if (_M_del) 59*e4b17023SJohn Marino delete[] this->table(); 60*e4b17023SJohn Marino } 61*e4b17023SJohn Marino 62*e4b17023SJohn Marino // Fill in the narrowing cache and flag whether all values are 63*e4b17023SJohn Marino // valid or not. _M_narrow_ok is set to 2 if memcpy can't 64*e4b17023SJohn Marino // be used. 65*e4b17023SJohn Marino void 66*e4b17023SJohn Marino ctype<char>:: _M_narrow_init() const67*e4b17023SJohn Marino _M_narrow_init() const 68*e4b17023SJohn Marino { 69*e4b17023SJohn Marino char __tmp[sizeof(_M_narrow)]; 70*e4b17023SJohn Marino for (size_t __i = 0; __i < sizeof(_M_narrow); ++__i) 71*e4b17023SJohn Marino __tmp[__i] = __i; 72*e4b17023SJohn Marino do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow); 73*e4b17023SJohn Marino 74*e4b17023SJohn Marino _M_narrow_ok = 1; 75*e4b17023SJohn Marino if (__builtin_memcmp(__tmp, _M_narrow, sizeof(_M_narrow))) 76*e4b17023SJohn Marino _M_narrow_ok = 2; 77*e4b17023SJohn Marino else 78*e4b17023SJohn Marino { 79*e4b17023SJohn Marino // Deal with the special case of zero: renarrow with a 80*e4b17023SJohn Marino // different default and compare. 81*e4b17023SJohn Marino char __c; 82*e4b17023SJohn Marino do_narrow(__tmp, __tmp + 1, 1, &__c); 83*e4b17023SJohn Marino if (__c == 1) 84*e4b17023SJohn Marino _M_narrow_ok = 2; 85*e4b17023SJohn Marino } 86*e4b17023SJohn Marino } 87*e4b17023SJohn Marino 88*e4b17023SJohn Marino void 89*e4b17023SJohn Marino ctype<char>:: _M_widen_init() const90*e4b17023SJohn Marino _M_widen_init() const 91*e4b17023SJohn Marino { 92*e4b17023SJohn Marino char __tmp[sizeof(_M_widen)]; 93*e4b17023SJohn Marino for (size_t __i = 0; __i < sizeof(_M_widen); ++__i) 94*e4b17023SJohn Marino __tmp[__i] = __i; 95*e4b17023SJohn Marino do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen); 96*e4b17023SJohn Marino 97*e4b17023SJohn Marino _M_widen_ok = 1; 98*e4b17023SJohn Marino // Set _M_widen_ok to 2 if memcpy can't be used. 99*e4b17023SJohn Marino if (__builtin_memcmp(__tmp, _M_widen, sizeof(_M_widen))) 100*e4b17023SJohn Marino _M_widen_ok = 2; 101*e4b17023SJohn Marino } 102*e4b17023SJohn Marino 103*e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T ctype(size_t __refs)104*e4b17023SJohn Marino ctype<wchar_t>::ctype(size_t __refs) 105*e4b17023SJohn Marino : __ctype_abstract_base<wchar_t>(__refs), 106*e4b17023SJohn Marino _M_c_locale_ctype(_S_get_c_locale()), _M_narrow_ok(false) 107*e4b17023SJohn Marino { _M_initialize_ctype(); } 108*e4b17023SJohn Marino ctype(__c_locale __cloc,size_t __refs)109*e4b17023SJohn Marino ctype<wchar_t>::ctype(__c_locale __cloc, size_t __refs) 110*e4b17023SJohn Marino : __ctype_abstract_base<wchar_t>(__refs), 111*e4b17023SJohn Marino _M_c_locale_ctype(_S_clone_c_locale(__cloc)), _M_narrow_ok(false) 112*e4b17023SJohn Marino { _M_initialize_ctype(); } 113*e4b17023SJohn Marino ~ctype()114*e4b17023SJohn Marino ctype<wchar_t>::~ctype() 115*e4b17023SJohn Marino { _S_destroy_c_locale(_M_c_locale_ctype); } 116*e4b17023SJohn Marino ctype_byname(const char * __s,size_t __refs)117*e4b17023SJohn Marino ctype_byname<wchar_t>::ctype_byname(const char* __s, size_t __refs) 118*e4b17023SJohn Marino : ctype<wchar_t>(__refs) 119*e4b17023SJohn Marino { 120*e4b17023SJohn Marino if (std::strcmp(__s, "C") != 0 && std::strcmp(__s, "POSIX") != 0) 121*e4b17023SJohn Marino { 122*e4b17023SJohn Marino this->_S_destroy_c_locale(this->_M_c_locale_ctype); 123*e4b17023SJohn Marino this->_S_create_c_locale(this->_M_c_locale_ctype, __s); 124*e4b17023SJohn Marino this->_M_initialize_ctype(); 125*e4b17023SJohn Marino } 126*e4b17023SJohn Marino } 127*e4b17023SJohn Marino ~ctype_byname()128*e4b17023SJohn Marino ctype_byname<wchar_t>::~ctype_byname() 129*e4b17023SJohn Marino { } 130*e4b17023SJohn Marino 131*e4b17023SJohn Marino #endif 132*e4b17023SJohn Marino 133*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 134*e4b17023SJohn Marino } // namespace 135