1117397Skan// Locale support -*- C++ -*-
2117397Skan
3117397Skan// Copyright (C) 2004 Free Software Foundation, Inc.
4117397Skan//
5117397Skan// This file is part of the GNU ISO C++ Library.  This library is free
6117397Skan// software; you can redistribute it and/or modify it under the
7117397Skan// terms of the GNU General Public License as published by the
8117397Skan// Free Software Foundation; either version 2, or (at your option)
9117397Skan// any later version.
10117397Skan
11117397Skan// This library is distributed in the hope that it will be useful,
12117397Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of
13117397Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14117397Skan// GNU General Public License for more details.
15117397Skan
16117397Skan// You should have received a copy of the GNU General Public License along
17117397Skan// with this library; see the file COPYING.  If not, write to the Free
18117397Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19169691Skan// USA.
20117397Skan
21117397Skan// As a special exception, you may use this file as part of a free software
22117397Skan// library without restriction.  Specifically, if other files instantiate
23117397Skan// templates or use macros or inline functions from this file, or you compile
24117397Skan// this file and link it with other files to produce an executable, this
25117397Skan// file does not by itself cause the resulting executable to be covered by
26117397Skan// the GNU General Public License.  This exception does not however
27117397Skan// invalidate any other reasons why the executable file might be covered by
28117397Skan// the GNU General Public License.
29117397Skan
30117397Skan/** @file ctype_noninline.h
31169691Skan *  This is an internal header file, included by other library headers.
32169691Skan *  You should not attempt to use it directly.
33169691Skan */
34169691Skan
35169691Skan//
36117397Skan// ISO C++ 14882: 22.1  Locales
37117397Skan//
38117397Skan
39117397Skan// Information as gleaned from /usr/include/ctype.h
40117397Skan
41117397Skan  const ctype_base::mask*
42117397Skan  ctype<char>::classic_table() throw()
43117397Skan  {
44117397Skan    const ctype_base::mask* __ret;
45117397Skan    char* __old = strdup(setlocale(LC_CTYPE, NULL));
46117397Skan    setlocale(LC_CTYPE, "C");
47117397Skan    __ret = *__ctype_b_loc();
48132720Skan    setlocale(LC_CTYPE, __old);
49117397Skan    free(__old);
50117397Skan    return __ret;
51132720Skan  }
52132720Skan
53132720Skan  ctype<char>::ctype(__c_locale, const mask* __table, bool __del,
54132720Skan		     size_t __refs)
55132720Skan  : facet(__refs), _M_del(__table != 0 && __del)
56132720Skan  {
57117397Skan    char* __old=strdup(setlocale(LC_CTYPE, NULL));
58117397Skan    setlocale(LC_CTYPE, "C");
59132720Skan    _M_toupper = *__ctype_toupper_loc();
60117397Skan    _M_tolower = *__ctype_tolower_loc();
61117397Skan    _M_table = __table ? __table : *__ctype_b_loc();
62132720Skan    setlocale(LC_CTYPE, __old);
63132720Skan    free(__old);
64132720Skan    _M_c_locale_ctype = _S_get_c_locale();
65132720Skan  }
66132720Skan
67132720Skan  ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
68117397Skan  : facet(__refs), _M_del(__table != 0 && __del)
69117397Skan  {
70117397Skan    char* __old=strdup(setlocale(LC_CTYPE, NULL));
71117397Skan    setlocale(LC_CTYPE, "C");
72117397Skan    _M_toupper = *__ctype_toupper_loc();
73117397Skan    _M_tolower = *__ctype_tolower_loc();
74117397Skan    _M_table = __table ? __table : *__ctype_b_loc();
75117397Skan    setlocale(LC_CTYPE, __old);
76117397Skan    free(__old);
77117397Skan    _M_c_locale_ctype = _S_get_c_locale();
78117397Skan  }
79117397Skan
80117397Skan  char
81117397Skan  ctype<char>::do_toupper(char __c) const
82117397Skan  { return _M_toupper[static_cast<unsigned char>(__c)]; }
83117397Skan
84117397Skan  const char*
85117397Skan  ctype<char>::do_toupper(char* __low, const char* __high) const
86117397Skan  {
87117397Skan    while (__low < __high)
88117397Skan      {
89117397Skan	*__low = _M_toupper[static_cast<unsigned char>(*__low)];
90117397Skan	++__low;
91117397Skan      }
92117397Skan    return __high;
93117397Skan  }
94117397Skan
95117397Skan  char
96117397Skan  ctype<char>::do_tolower(char __c) const
97117397Skan  { return _M_tolower[static_cast<unsigned char>(__c)]; }
98
99  const char*
100  ctype<char>::do_tolower(char* __low, const char* __high) const
101  {
102    while (__low < __high)
103      {
104	*__low = _M_tolower[static_cast<unsigned char>(*__low)];
105	++__low;
106      }
107    return __high;
108  }
109