Blame ctype/ctype.h

Packit 6c4009
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 *	ISO C99 Standard 7.4: Character handling	<ctype.h>
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#ifndef	_CTYPE_H
Packit 6c4009
#define	_CTYPE_H	1
Packit 6c4009
Packit 6c4009
#include <features.h>
Packit 6c4009
#include <bits/types.h>
Packit 6c4009
Packit 6c4009
__BEGIN_DECLS
Packit 6c4009
Packit 6c4009
#ifndef _ISbit
Packit 6c4009
/* These are all the characteristics of characters.
Packit 6c4009
   If there get to be more than 16 distinct characteristics,
Packit 6c4009
   many things must be changed that use `unsigned short int's.
Packit 6c4009
Packit 6c4009
   The characteristics are stored always in network byte order (big
Packit 6c4009
   endian).  We define the bit value interpretations here dependent on the
Packit 6c4009
   machine's byte order.  */
Packit 6c4009
Packit 6c4009
# include <endian.h>
Packit 6c4009
# if __BYTE_ORDER == __BIG_ENDIAN
Packit 6c4009
#  define _ISbit(bit)	(1 << (bit))
Packit 6c4009
# else /* __BYTE_ORDER == __LITTLE_ENDIAN */
Packit 6c4009
#  define _ISbit(bit)	((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8))
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
enum
Packit 6c4009
{
Packit 6c4009
  _ISupper = _ISbit (0),	/* UPPERCASE.  */
Packit 6c4009
  _ISlower = _ISbit (1),	/* lowercase.  */
Packit 6c4009
  _ISalpha = _ISbit (2),	/* Alphabetic.  */
Packit 6c4009
  _ISdigit = _ISbit (3),	/* Numeric.  */
Packit 6c4009
  _ISxdigit = _ISbit (4),	/* Hexadecimal numeric.  */
Packit 6c4009
  _ISspace = _ISbit (5),	/* Whitespace.  */
Packit 6c4009
  _ISprint = _ISbit (6),	/* Printing.  */
Packit 6c4009
  _ISgraph = _ISbit (7),	/* Graphical.  */
Packit 6c4009
  _ISblank = _ISbit (8),	/* Blank (usually SPC and TAB).  */
Packit 6c4009
  _IScntrl = _ISbit (9),	/* Control character.  */
Packit 6c4009
  _ISpunct = _ISbit (10),	/* Punctuation.  */
Packit 6c4009
  _ISalnum = _ISbit (11)	/* Alphanumeric.  */
Packit 6c4009
};
Packit 6c4009
#endif /* ! _ISbit  */
Packit 6c4009
Packit 6c4009
/* These are defined in ctype-info.c.
Packit 6c4009
   The declarations here must match those in localeinfo.h.
Packit 6c4009
Packit 6c4009
   In the thread-specific locale model (see `uselocale' in <locale.h>)
Packit 6c4009
   we cannot use global variables for these as was done in the past.
Packit 6c4009
   Instead, the following accessor functions return the address of
Packit 6c4009
   each variable, which is local to the current thread if multithreaded.
Packit 6c4009
Packit 6c4009
   These point into arrays of 384, so they can be indexed by any `unsigned
Packit 6c4009
   char' value [0,255]; by EOF (-1); or by any `signed char' value
Packit 6c4009
   [-128,-1).  ISO C requires that the ctype functions work for `unsigned
Packit 6c4009
   char' values and for EOF; we also support negative `signed char' values
Packit 6c4009
   for broken old programs.  The case conversion arrays are of `int's
Packit 6c4009
   rather than `unsigned char's because tolower (EOF) must be EOF, which
Packit 6c4009
   doesn't fit into an `unsigned char'.  But today more important is that
Packit 6c4009
   the arrays are also used for multi-byte character sets.  */
Packit 6c4009
extern const unsigned short int **__ctype_b_loc (void)
Packit 6c4009
     __THROW __attribute__ ((__const__));
Packit 6c4009
extern const __int32_t **__ctype_tolower_loc (void)
Packit 6c4009
     __THROW __attribute__ ((__const__));
Packit 6c4009
extern const __int32_t **__ctype_toupper_loc (void)
Packit 6c4009
     __THROW __attribute__ ((__const__));
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifndef __cplusplus
Packit 6c4009
# define __isctype(c, type) \
Packit 6c4009
  ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)
Packit 6c4009
#elif defined __USE_EXTERN_INLINES
Packit 6c4009
# define __isctype_f(type) \
Packit 6c4009
  __extern_inline int							      \
Packit 6c4009
  is##type (int __c) __THROW						      \
Packit 6c4009
  {									      \
Packit 6c4009
    return (*__ctype_b_loc ())[(int) (__c)] & (unsigned short int) _IS##type; \
Packit 6c4009
  }
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#define	__isascii(c)	(((c) & ~0x7f) == 0)	/* If C is a 7 bit value.  */
Packit 6c4009
#define	__toascii(c)	((c) & 0x7f)		/* Mask off high bits.  */
Packit 6c4009
Packit 6c4009
#define	__exctype(name)	extern int name (int) __THROW
Packit 6c4009
Packit 6c4009
/* The following names are all functions:
Packit 6c4009
     int isCHARACTERISTIC(int c);
Packit 6c4009
   which return nonzero iff C has CHARACTERISTIC.
Packit 6c4009
   For the meaning of the characteristic names, see the `enum' above.  */
Packit 6c4009
__exctype (isalnum);
Packit 6c4009
__exctype (isalpha);
Packit 6c4009
__exctype (iscntrl);
Packit 6c4009
__exctype (isdigit);
Packit 6c4009
__exctype (islower);
Packit 6c4009
__exctype (isgraph);
Packit 6c4009
__exctype (isprint);
Packit 6c4009
__exctype (ispunct);
Packit 6c4009
__exctype (isspace);
Packit 6c4009
__exctype (isupper);
Packit 6c4009
__exctype (isxdigit);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Return the lowercase version of C.  */
Packit 6c4009
extern int tolower (int __c) __THROW;
Packit 6c4009
Packit 6c4009
/* Return the uppercase version of C.  */
Packit 6c4009
extern int toupper (int __c) __THROW;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* ISO C99 introduced one new function.  */
Packit 6c4009
#ifdef	__USE_ISOC99
Packit 6c4009
__exctype (isblank);
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#ifdef __USE_GNU
Packit 6c4009
/* Test C for a set of character classes according to MASK.  */
Packit 6c4009
extern int isctype (int __c, int __mask) __THROW;
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#if defined __USE_MISC || defined __USE_XOPEN
Packit 6c4009
Packit 6c4009
/* Return nonzero iff C is in the ASCII set
Packit 6c4009
   (i.e., is no more than 7 bits wide).  */
Packit 6c4009
extern int isascii (int __c) __THROW;
Packit 6c4009
Packit 6c4009
/* Return the part of C that is in the ASCII set
Packit 6c4009
   (i.e., the low-order 7 bits of C).  */
Packit 6c4009
extern int toascii (int __c) __THROW;
Packit 6c4009
Packit 6c4009
/* These are the same as `toupper' and `tolower' except that they do not
Packit 6c4009
   check the argument for being in the range of a `char'.  */
Packit 6c4009
__exctype (_toupper);
Packit 6c4009
__exctype (_tolower);
Packit 6c4009
#endif /* Use X/Open or use misc.  */
Packit 6c4009
Packit 6c4009
/* This code is needed for the optimized mapping functions.  */
Packit 6c4009
#define __tobody(c, f, a, args) \
Packit 6c4009
  (__extension__							      \
Packit 6c4009
   ({ int __res;							      \
Packit 6c4009
      if (sizeof (c) > 1)						      \
Packit 6c4009
	{								      \
Packit 6c4009
	  if (__builtin_constant_p (c))					      \
Packit 6c4009
	    {								      \
Packit 6c4009
	      int __c = (c);						      \
Packit 6c4009
	      __res = __c < -128 || __c > 255 ? __c : (a)[__c];		      \
Packit 6c4009
	    }								      \
Packit 6c4009
	  else								      \
Packit 6c4009
	    __res = f args;						      \
Packit 6c4009
	}								      \
Packit 6c4009
      else								      \
Packit 6c4009
	__res = (a)[(int) (c)];						      \
Packit 6c4009
      __res; }))
Packit 6c4009
Packit 6c4009
#if !defined __NO_CTYPE
Packit 6c4009
# ifdef __isctype_f
Packit 6c4009
__isctype_f (alnum)
Packit 6c4009
__isctype_f (alpha)
Packit 6c4009
__isctype_f (cntrl)
Packit 6c4009
__isctype_f (digit)
Packit 6c4009
__isctype_f (lower)
Packit 6c4009
__isctype_f (graph)
Packit 6c4009
__isctype_f (print)
Packit 6c4009
__isctype_f (punct)
Packit 6c4009
__isctype_f (space)
Packit 6c4009
__isctype_f (upper)
Packit 6c4009
__isctype_f (xdigit)
Packit 6c4009
#  ifdef __USE_ISOC99
Packit 6c4009
__isctype_f (blank)
Packit 6c4009
#  endif
Packit 6c4009
# elif defined __isctype
Packit 6c4009
# define isalnum(c)	__isctype((c), _ISalnum)
Packit 6c4009
# define isalpha(c)	__isctype((c), _ISalpha)
Packit 6c4009
# define iscntrl(c)	__isctype((c), _IScntrl)
Packit 6c4009
# define isdigit(c)	__isctype((c), _ISdigit)
Packit 6c4009
# define islower(c)	__isctype((c), _ISlower)
Packit 6c4009
# define isgraph(c)	__isctype((c), _ISgraph)
Packit 6c4009
# define isprint(c)	__isctype((c), _ISprint)
Packit 6c4009
# define ispunct(c)	__isctype((c), _ISpunct)
Packit 6c4009
# define isspace(c)	__isctype((c), _ISspace)
Packit 6c4009
# define isupper(c)	__isctype((c), _ISupper)
Packit 6c4009
# define isxdigit(c)	__isctype((c), _ISxdigit)
Packit 6c4009
#  ifdef __USE_ISOC99
Packit 6c4009
#   define isblank(c)	__isctype((c), _ISblank)
Packit 6c4009
#  endif
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# ifdef __USE_EXTERN_INLINES
Packit 6c4009
__extern_inline int
Packit 6c4009
__NTH (tolower (int __c))
Packit 6c4009
{
Packit 6c4009
  return __c >= -128 && __c < 256 ? (*__ctype_tolower_loc ())[__c] : __c;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
__extern_inline int
Packit 6c4009
__NTH (toupper (int __c))
Packit 6c4009
{
Packit 6c4009
  return __c >= -128 && __c < 256 ? (*__ctype_toupper_loc ())[__c] : __c;
Packit 6c4009
}
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
# if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
Packit 6c4009
#  define tolower(c)	__tobody (c, tolower, *__ctype_tolower_loc (), (c))
Packit 6c4009
#  define toupper(c)	__tobody (c, toupper, *__ctype_toupper_loc (), (c))
Packit 6c4009
# endif /* Optimizing gcc */
Packit 6c4009
Packit 6c4009
# if defined __USE_MISC || defined __USE_XOPEN
Packit 6c4009
#  define isascii(c)	__isascii (c)
Packit 6c4009
#  define toascii(c)	__toascii (c)
Packit 6c4009
Packit 6c4009
#  define _tolower(c)	((int) (*__ctype_tolower_loc ())[(int) (c)])
Packit 6c4009
#  define _toupper(c)	((int) (*__ctype_toupper_loc ())[(int) (c)])
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
#endif /* Not __NO_CTYPE.  */
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifdef __USE_XOPEN2K8
Packit 6c4009
/* POSIX.1-2008 extended locale interface (see locale.h).  */
Packit 6c4009
# include <bits/types/locale_t.h>
Packit 6c4009
Packit 6c4009
/* These definitions are similar to the ones above but all functions
Packit 6c4009
   take as an argument a handle for the locale which shall be used.  */
Packit 6c4009
#  define __isctype_l(c, type, locale) \
Packit 6c4009
  ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
Packit 6c4009
Packit 6c4009
# define __exctype_l(name) 						      \
Packit 6c4009
  extern int name (int, locale_t) __THROW
Packit 6c4009
Packit 6c4009
/* The following names are all functions:
Packit 6c4009
     int isCHARACTERISTIC(int c, locale_t *locale);
Packit 6c4009
   which return nonzero iff C has CHARACTERISTIC.
Packit 6c4009
   For the meaning of the characteristic names, see the `enum' above.  */
Packit 6c4009
__exctype_l (isalnum_l);
Packit 6c4009
__exctype_l (isalpha_l);
Packit 6c4009
__exctype_l (iscntrl_l);
Packit 6c4009
__exctype_l (isdigit_l);
Packit 6c4009
__exctype_l (islower_l);
Packit 6c4009
__exctype_l (isgraph_l);
Packit 6c4009
__exctype_l (isprint_l);
Packit 6c4009
__exctype_l (ispunct_l);
Packit 6c4009
__exctype_l (isspace_l);
Packit 6c4009
__exctype_l (isupper_l);
Packit 6c4009
__exctype_l (isxdigit_l);
Packit 6c4009
Packit 6c4009
__exctype_l (isblank_l);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Return the lowercase version of C in locale L.  */
Packit 6c4009
extern int __tolower_l (int __c, locale_t __l) __THROW;
Packit 6c4009
extern int tolower_l (int __c, locale_t __l) __THROW;
Packit 6c4009
Packit 6c4009
/* Return the uppercase version of C.  */
Packit 6c4009
extern int __toupper_l (int __c, locale_t __l) __THROW;
Packit 6c4009
extern int toupper_l (int __c, locale_t __l) __THROW;
Packit 6c4009
Packit 6c4009
# if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
Packit 6c4009
#  define __tolower_l(c, locale) \
Packit 6c4009
  __tobody (c, __tolower_l, (locale)->__ctype_tolower, (c, locale))
Packit 6c4009
#  define __toupper_l(c, locale) \
Packit 6c4009
  __tobody (c, __toupper_l, (locale)->__ctype_toupper, (c, locale))
Packit 6c4009
#  define tolower_l(c, locale)	__tolower_l ((c), (locale))
Packit 6c4009
#  define toupper_l(c, locale)	__toupper_l ((c), (locale))
Packit 6c4009
# endif	/* Optimizing gcc */
Packit 6c4009
Packit 6c4009
Packit 6c4009
# ifndef __NO_CTYPE
Packit 6c4009
#  define __isalnum_l(c,l)	__isctype_l((c), _ISalnum, (l))
Packit 6c4009
#  define __isalpha_l(c,l)	__isctype_l((c), _ISalpha, (l))
Packit 6c4009
#  define __iscntrl_l(c,l)	__isctype_l((c), _IScntrl, (l))
Packit 6c4009
#  define __isdigit_l(c,l)	__isctype_l((c), _ISdigit, (l))
Packit 6c4009
#  define __islower_l(c,l)	__isctype_l((c), _ISlower, (l))
Packit 6c4009
#  define __isgraph_l(c,l)	__isctype_l((c), _ISgraph, (l))
Packit 6c4009
#  define __isprint_l(c,l)	__isctype_l((c), _ISprint, (l))
Packit 6c4009
#  define __ispunct_l(c,l)	__isctype_l((c), _ISpunct, (l))
Packit 6c4009
#  define __isspace_l(c,l)	__isctype_l((c), _ISspace, (l))
Packit 6c4009
#  define __isupper_l(c,l)	__isctype_l((c), _ISupper, (l))
Packit 6c4009
#  define __isxdigit_l(c,l)	__isctype_l((c), _ISxdigit, (l))
Packit 6c4009
Packit 6c4009
#  define __isblank_l(c,l)	__isctype_l((c), _ISblank, (l))
Packit 6c4009
Packit 6c4009
#  ifdef __USE_MISC
Packit 6c4009
#   define __isascii_l(c,l)	((l), __isascii (c))
Packit 6c4009
#   define __toascii_l(c,l)	((l), __toascii (c))
Packit 6c4009
#  endif
Packit 6c4009
Packit 6c4009
#  define isalnum_l(c,l)	__isalnum_l ((c), (l))
Packit 6c4009
#  define isalpha_l(c,l)	__isalpha_l ((c), (l))
Packit 6c4009
#  define iscntrl_l(c,l)	__iscntrl_l ((c), (l))
Packit 6c4009
#  define isdigit_l(c,l)	__isdigit_l ((c), (l))
Packit 6c4009
#  define islower_l(c,l)	__islower_l ((c), (l))
Packit 6c4009
#  define isgraph_l(c,l)	__isgraph_l ((c), (l))
Packit 6c4009
#  define isprint_l(c,l)	__isprint_l ((c), (l))
Packit 6c4009
#  define ispunct_l(c,l)	__ispunct_l ((c), (l))
Packit 6c4009
#  define isspace_l(c,l)	__isspace_l ((c), (l))
Packit 6c4009
#  define isupper_l(c,l)	__isupper_l ((c), (l))
Packit 6c4009
#  define isxdigit_l(c,l)	__isxdigit_l ((c), (l))
Packit 6c4009
Packit 6c4009
#  define isblank_l(c,l)	__isblank_l ((c), (l))
Packit 6c4009
Packit 6c4009
#  ifdef __USE_MISC
Packit 6c4009
#   define isascii_l(c,l)	__isascii_l ((c), (l))
Packit 6c4009
#   define toascii_l(c,l)	__toascii_l ((c), (l))
Packit 6c4009
#  endif
Packit 6c4009
Packit 6c4009
# endif /* Not __NO_CTYPE.  */
Packit 6c4009
Packit 6c4009
#endif /* Use POSIX 2008.  */
Packit 6c4009
Packit 6c4009
__END_DECLS
Packit 6c4009
Packit 6c4009
#endif /* ctype.h  */