ctype_inline.h revision 117397
1100364Smarkm// Locale support -*- C++ -*-
212099Sjoerg
312099Sjoerg// Copyright (C) 2000, 2003 Free Software Foundation, Inc.
412099Sjoerg//
512099Sjoerg// This file is part of the GNU ISO C++ Library.  This library is free
612099Sjoerg// software; you can redistribute it and/or modify it under the
712099Sjoerg// terms of the GNU General Public License as published by the
812099Sjoerg// Free Software Foundation; either version 2, or (at your option)
912099Sjoerg// any later version.
1012099Sjoerg
1112099Sjoerg// This library is distributed in the hope that it will be useful,
1212099Sjoerg// but WITHOUT ANY WARRANTY; without even the implied warranty of
1312099Sjoerg// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1412099Sjoerg// GNU General Public License for more details.
1512099Sjoerg
1612099Sjoerg// You should have received a copy of the GNU General Public License along
1712099Sjoerg// with this library; see the file COPYING.  If not, write to the Free
1812099Sjoerg// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1912099Sjoerg// USA.
2012099Sjoerg
2112099Sjoerg// As a special exception, you may use this file as part of a free software
2212099Sjoerg// library without restriction.  Specifically, if other files instantiate
2312099Sjoerg// templates or use macros or inline functions from this file, or you compile
2412099Sjoerg// this file and link it with other files to produce an executable, this
2512099Sjoerg// file does not by itself cause the resulting executable to be covered by
2612099Sjoerg// the GNU General Public License.  This exception does not however
2712099Sjoerg// invalidate any other reasons why the executable file might be covered by
2812099Sjoerg// the GNU General Public License.
2912099Sjoerg
3012099Sjoerg//
3112099Sjoerg// ISO C++ 14882: 22.1  Locales
3212099Sjoerg//
3312099Sjoerg
3491592Smarkm// ctype bits to be inlined go here. Non-inlinable (ie virtual do_*)
3591592Smarkm// functions go in ctype.cc
36100364Smarkm
3712099Sjoerg  bool
3891592Smarkm  ctype<char>::
3912099Sjoerg  is(mask __m, char __c) const
4012099Sjoerg  {
4112099Sjoerg    if (_M_table)
4212099Sjoerg      return _M_table[static_cast<unsigned char>(__c)] & __m;
43148723Sstefanf    else
4412099Sjoerg      return __istype(__c, __m);
4512099Sjoerg  }
4612099Sjoerg
4712099Sjoerg  const char*
4812099Sjoerg  ctype<char>::
4912099Sjoerg  is(const char* __low, const char* __high, mask* __vec) const
5012099Sjoerg  {
5112099Sjoerg    if (_M_table)
5212099Sjoerg      while (__low < __high)
5312099Sjoerg	*__vec++ = _M_table[static_cast<unsigned char>(*__low++)];
5412099Sjoerg    else
5512099Sjoerg      for (;__low < __high; ++__vec, ++__low)
5612099Sjoerg	{
5712099Sjoerg#if defined (_CTYPE_S) || defined (__istype)
5812099Sjoerg	  *__vec = __maskrune (*__low, upper | lower | alpha | digit | xdigit
5912099Sjoerg			       | space | print | graph | cntrl | punct | alnum);
6012099Sjoerg#else
6112099Sjoerg	  mask __m = 0;
6291592Smarkm	  if (this->is(upper, *__low)) __m |= upper;
6312099Sjoerg	  if (this->is(lower, *__low)) __m |= lower;
6412099Sjoerg	  if (this->is(alpha, *__low)) __m |= alpha;
6512099Sjoerg	  if (this->is(digit, *__low)) __m |= digit;
6612099Sjoerg	  if (this->is(xdigit, *__low)) __m |= xdigit;
6712099Sjoerg	  if (this->is(space, *__low)) __m |= space;
6891592Smarkm	  if (this->is(print, *__low)) __m |= print;
6912099Sjoerg	  if (this->is(graph, *__low)) __m |= graph;
7012099Sjoerg	  if (this->is(cntrl, *__low)) __m |= cntrl;
7112099Sjoerg	  if (this->is(punct, *__low)) __m |= punct;
7212099Sjoerg	  // Do not include explicit line for alnum mask since it is a
7312099Sjoerg	  // pure composite of masks on FreeBSD.
7412099Sjoerg	  *__vec = __m;
7512099Sjoerg#endif
7612099Sjoerg	}
7712099Sjoerg    return __high;
7812099Sjoerg  }
7912099Sjoerg
8012099Sjoerg  const char*
8112099Sjoerg  ctype<char>::
8212099Sjoerg  scan_is(mask __m, const char* __low, const char* __high) const
8391592Smarkm  {
8412099Sjoerg    if (_M_table)
8591592Smarkm      while (__low < __high
8612099Sjoerg	     && !(_M_table[static_cast<unsigned char>(*__low)] & __m))
8712099Sjoerg	++__low;
8812099Sjoerg    else
8912099Sjoerg      while (__low < __high && !this->is(__m, *__low))
9091592Smarkm	++__low;
9112099Sjoerg    return __low;
9212099Sjoerg  }
9312099Sjoerg
9412099Sjoerg  const char*
9512099Sjoerg  ctype<char>::
9612099Sjoerg  scan_not(mask __m, const char* __low, const char* __high) const
9712099Sjoerg  {
9812099Sjoerg    if (_M_table)
9912099Sjoerg      while (__low < __high
10080284Sobrien	     && (_M_table[static_cast<unsigned char>(*__low)] & __m) != 0)
10180284Sobrien	++__low;
10212099Sjoerg    else
10380284Sobrien      while (__low < __high && this->is(__m, *__low) != 0)
10480284Sobrien	++__low;
10512099Sjoerg    return __low;
10612099Sjoerg  }
10712099Sjoerg