1117397Skan// Locale support -*- C++ -*-
2117397Skan
3117397Skan// Copyright (C) 2002 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
18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19117397Skan// 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
30169691Skan/** @file ctype_inline.h
31169691Skan *  This is an internal header file, included by other library headers.
32169691Skan *  You should not attempt to use it directly.
33169691Skan */
34169691Skan
35117397Skan//
36117397Skan// ISO C++ 14882: 22.1  Locales
37117397Skan//
38117397Skan
39117397Skan// ctype bits to be inlined go here. Non-inlinable (ie virtual do_*)
40117397Skan// functions go in ctype.cc
41117397Skan
42117397Skan// The following definitions are portable, but insanely slow. If one
43117397Skan// cares at all about performance, then specialized ctype
44117397Skan// functionality should be added for the native os in question: see
45117397Skan// the config/os/bits/ctype_*.h files.
46117397Skan
47169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
48169691Skan
49117397Skan  bool
50117397Skan  ctype<char>::
51117397Skan  is(mask __m, char __c) const
52117397Skan  {
53117397Skan    bool __ret;
54117397Skan    switch (__m)
55117397Skan      {
56117397Skan      case space:
57117397Skan	__ret = isspace(__c);
58117397Skan	break;
59117397Skan      case print:
60117397Skan	__ret = isprint(__c);
61117397Skan	break;
62117397Skan      case cntrl:
63117397Skan	__ret = iscntrl(__c);
64117397Skan	break;
65117397Skan      case upper:
66117397Skan	__ret = isupper(__c);
67117397Skan	break;
68117397Skan      case lower:
69117397Skan	__ret = islower(__c);
70117397Skan	break;
71117397Skan      case alpha:
72117397Skan	__ret = isalpha(__c);
73117397Skan	break;
74117397Skan      case digit:
75117397Skan	__ret = isdigit(__c);
76117397Skan	break;
77117397Skan      case punct:
78117397Skan	__ret = ispunct(__c);
79117397Skan	break;
80117397Skan      case xdigit:
81117397Skan	__ret = isxdigit(__c);
82117397Skan	break;
83117397Skan      case alnum:
84117397Skan	__ret = isalnum(__c);
85117397Skan	break;
86117397Skan      case graph:
87117397Skan	__ret = isgraph(__c);
88117397Skan	break;
89117397Skan      default:
90117397Skan	__ret = false;
91117397Skan	break;
92117397Skan      }
93117397Skan    return __ret;
94117397Skan  }
95117397Skan
96117397Skan  const char*
97117397Skan  ctype<char>::
98117397Skan  is(const char* __low, const char* __high, mask* __vec) const
99117397Skan  {
100117397Skan    const int __bitmasksize = 11; // Highest bitmask in ctype_base == 10
101117397Skan    for (;__low < __high; ++__vec, ++__low)
102117397Skan      {
103117397Skan	mask __m = 0;
104117397Skan	int __i = 0; // Lowest bitmask in ctype_base == 0
105117397Skan	for (;__i < __bitmasksize; ++__i)
106117397Skan	  {
107117397Skan	    mask __bit = static_cast<mask>(1 << __i);
108117397Skan	    if (this->is(__bit, *__low))
109117397Skan	      __m |= __bit;
110117397Skan	  }
111117397Skan	*__vec = __m;
112117397Skan      }
113117397Skan    return __high;
114117397Skan  }
115117397Skan
116117397Skan  const char*
117117397Skan  ctype<char>::
118117397Skan  scan_is(mask __m, const char* __low, const char* __high) const
119117397Skan  {
120117397Skan    while (__low < __high && !this->is(__m, *__low))
121117397Skan      ++__low;
122117397Skan    return __low;
123117397Skan  }
124117397Skan
125117397Skan  const char*
126117397Skan  ctype<char>::
127117397Skan  scan_not(mask __m, const char* __low, const char* __high) const
128117397Skan  {
129117397Skan    while (__low < __high && this->is(__m, *__low) != 0)
130117397Skan      ++__low;
131117397Skan    return __low;
132117397Skan  }
133169691Skan
134169691Skan_GLIBCXX_END_NAMESPACE
135