1169691Skan// Locale support -*- C++ -*-
2169691Skan
3169691Skan// Copyright (C) 2000, 2003, 2004 Free Software Foundation, Inc.
4169691Skan//
5169691Skan// This file is part of the GNU ISO C++ Library.  This library is free
6169691Skan// software; you can redistribute it and/or modify it under the
7169691Skan// terms of the GNU General Public License as published by the
8169691Skan// Free Software Foundation; either version 2, or (at your option)
9169691Skan// any later version.
10169691Skan
11169691Skan// This library is distributed in the hope that it will be useful,
12169691Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of
13169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14169691Skan// GNU General Public License for more details.
15169691Skan
16169691Skan// You should have received a copy of the GNU General Public License along
17169691Skan// 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,
19169691Skan// USA.
20169691Skan
21169691Skan// As a special exception, you may use this file as part of a free software
22169691Skan// library without restriction.  Specifically, if other files instantiate
23169691Skan// templates or use macros or inline functions from this file, or you compile
24169691Skan// this file and link it with other files to produce an executable, this
25169691Skan// file does not by itself cause the resulting executable to be covered by
26169691Skan// the GNU General Public License.  This exception does not however
27169691Skan// invalidate any other reasons why the executable file might be covered by
28169691Skan// the GNU General Public License.
29169691Skan
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
35169691Skan//
36169691Skan// ISO C++ 14882: 22.1  Locales
37169691Skan//
38169691Skan
39169691Skan// ctype bits to be inlined go here. Non-inlinable (ie virtual do_*)
40169691Skan// functions go in ctype.cc
41169691Skan
42169691Skan_GLIBCXX_BEGIN_NAMESPACE(std)
43169691Skan
44169691Skan  bool
45169691Skan  ctype<char>::
46169691Skan  is(mask __m, char __c) const
47169691Skan  {
48169691Skan    if (_M_table)
49169691Skan      return _M_table[static_cast<unsigned char>(__c)] & __m;
50169691Skan    else
51169691Skan      return __istype(__c, __m);
52169691Skan  }
53169691Skan
54169691Skan  const char*
55169691Skan  ctype<char>::
56169691Skan  is(const char* __low, const char* __high, mask* __vec) const
57169691Skan  {
58169691Skan    if (_M_table)
59169691Skan      while (__low < __high)
60169691Skan	*__vec++ = _M_table[static_cast<unsigned char>(*__low++)];
61169691Skan    else
62169691Skan      for (;__low < __high; ++__vec, ++__low)
63169691Skan	{
64169691Skan#if defined (_CTYPE_S) || defined (__istype)
65169691Skan	  *__vec = __maskrune (*__low, upper | lower | alpha | digit | xdigit
66169691Skan			       | space | print | graph | cntrl | punct | alnum);
67169691Skan#else
68169691Skan	  mask __m = 0;
69169691Skan	  if (this->is(upper, *__low)) __m |= upper;
70169691Skan	  if (this->is(lower, *__low)) __m |= lower;
71169691Skan	  if (this->is(alpha, *__low)) __m |= alpha;
72169691Skan	  if (this->is(digit, *__low)) __m |= digit;
73169691Skan	  if (this->is(xdigit, *__low)) __m |= xdigit;
74169691Skan	  if (this->is(space, *__low)) __m |= space;
75169691Skan	  if (this->is(print, *__low)) __m |= print;
76169691Skan	  if (this->is(graph, *__low)) __m |= graph;
77169691Skan	  if (this->is(cntrl, *__low)) __m |= cntrl;
78169691Skan	  if (this->is(punct, *__low)) __m |= punct;
79169691Skan	  // Do not include explicit line for alnum mask since it is a
80169691Skan	  // pure composite of masks on FreeBSD.
81169691Skan	  *__vec = __m;
82169691Skan#endif
83169691Skan	}
84169691Skan    return __high;
85169691Skan  }
86169691Skan
87169691Skan  const char*
88169691Skan  ctype<char>::
89169691Skan  scan_is(mask __m, const char* __low, const char* __high) const
90169691Skan  {
91169691Skan    if (_M_table)
92169691Skan      while (__low < __high
93169691Skan	     && !(_M_table[static_cast<unsigned char>(*__low)] & __m))
94169691Skan	++__low;
95169691Skan    else
96169691Skan      while (__low < __high && !this->is(__m, *__low))
97169691Skan	++__low;
98169691Skan    return __low;
99169691Skan  }
100169691Skan
101169691Skan  const char*
102169691Skan  ctype<char>::
103169691Skan  scan_not(mask __m, const char* __low, const char* __high) const
104169691Skan  {
105169691Skan    if (_M_table)
106169691Skan      while (__low < __high
107169691Skan	     && (_M_table[static_cast<unsigned char>(*__low)] & __m) != 0)
108169691Skan	++__low;
109169691Skan    else
110169691Skan      while (__low < __high && this->is(__m, *__low) != 0)
111169691Skan	++__low;
112169691Skan    return __low;
113169691Skan  }
114169691Skan
115169691Skan#ifdef _GLIBCXX_USE_WCHAR_T
116169691Skan  inline bool
117169691Skan  ctype<wchar_t>::
118169691Skan  do_is(mask __m, wchar_t __c) const
119169691Skan  {
120169691Skan    return __istype (__c, __m);
121169691Skan  }
122169691Skan
123169691Skan  inline const wchar_t*
124169691Skan  ctype<wchar_t>::
125169691Skan  do_is(const wchar_t* __lo, const wchar_t* __hi, mask* __vec) const
126169691Skan  {
127169691Skan    for (; __lo < __hi; ++__vec, ++__lo)
128169691Skan      *__vec = __maskrune (*__lo, upper | lower | alpha | digit | xdigit
129169691Skan			   | space | print | graph | cntrl | punct | alnum);
130169691Skan    return __hi;
131169691Skan  }
132169691Skan
133169691Skan  inline const wchar_t*
134169691Skan  ctype<wchar_t>::
135169691Skan  do_scan_is(mask __m, const wchar_t* __lo, const wchar_t* __hi) const
136169691Skan  {
137169691Skan    while (__lo < __hi && ! __istype (*__lo, __m))
138169691Skan      ++__lo;
139169691Skan    return __lo;
140169691Skan  }
141169691Skan
142169691Skan  inline const wchar_t*
143169691Skan  ctype<wchar_t>::
144169691Skan  do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
145169691Skan  {
146169691Skan    while (__lo < __hi && __istype (*__lo, __m))
147169691Skan      ++__lo;
148169691Skan    return __lo;
149169691Skan  }
150169691Skan#endif
151169691Skan
152169691Skan_GLIBCXX_END_NAMESPACE
153