1// Locale support -*- C++ -*-
2
3// Copyright (C) 2002 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library.  This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING.  If not, write to the Free
18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19// USA.
20
21// As a special exception, you may use this file as part of a free software
22// library without restriction.  Specifically, if other files instantiate
23// templates or use macros or inline functions from this file, or you compile
24// this file and link it with other files to produce an executable, this
25// file does not by itself cause the resulting executable to be covered by
26// the GNU General Public License.  This exception does not however
27// invalidate any other reasons why the executable file might be covered by
28// the GNU General Public License.
29
30/** @file ctype_inline.h
31 *  This is an internal header file, included by other library headers.
32 *  You should not attempt to use it directly.
33 */
34
35//
36// ISO C++ 14882: 22.1  Locales
37//
38
39// ctype bits to be inlined go here. Non-inlinable (ie virtual do_*)
40// functions go in ctype.cc
41
42// The following definitions are portable, but insanely slow. If one
43// cares at all about performance, then specialized ctype
44// functionality should be added for the native os in question: see
45// the config/os/bits/ctype_*.h files.
46
47_GLIBCXX_BEGIN_NAMESPACE(std)
48
49  bool
50  ctype<char>::
51  is(mask __m, char __c) const
52  {
53    bool __ret;
54    switch (__m)
55      {
56      case space:
57	__ret = isspace(__c);
58	break;
59      case print:
60	__ret = isprint(__c);
61	break;
62      case cntrl:
63	__ret = iscntrl(__c);
64	break;
65      case upper:
66	__ret = isupper(__c);
67	break;
68      case lower:
69	__ret = islower(__c);
70	break;
71      case alpha:
72	__ret = isalpha(__c);
73	break;
74      case digit:
75	__ret = isdigit(__c);
76	break;
77      case punct:
78	__ret = ispunct(__c);
79	break;
80      case xdigit:
81	__ret = isxdigit(__c);
82	break;
83      case alnum:
84	__ret = isalnum(__c);
85	break;
86      case graph:
87	__ret = isgraph(__c);
88	break;
89      default:
90	__ret = false;
91	break;
92      }
93    return __ret;
94  }
95
96  const char*
97  ctype<char>::
98  is(const char* __low, const char* __high, mask* __vec) const
99  {
100    const int __bitmasksize = 11; // Highest bitmask in ctype_base == 10
101    for (;__low < __high; ++__vec, ++__low)
102      {
103	mask __m = 0;
104	int __i = 0; // Lowest bitmask in ctype_base == 0
105	for (;__i < __bitmasksize; ++__i)
106	  {
107	    mask __bit = static_cast<mask>(1 << __i);
108	    if (this->is(__bit, *__low))
109	      __m |= __bit;
110	  }
111	*__vec = __m;
112      }
113    return __high;
114  }
115
116  const char*
117  ctype<char>::
118  scan_is(mask __m, const char* __low, const char* __high) const
119  {
120    while (__low < __high && !this->is(__m, *__low))
121      ++__low;
122    return __low;
123  }
124
125  const char*
126  ctype<char>::
127  scan_not(mask __m, const char* __low, const char* __high) const
128  {
129    while (__low < __high && this->is(__m, *__low) != 0)
130      ++__low;
131    return __low;
132  }
133
134_GLIBCXX_END_NAMESPACE
135