ctype.h revision 51f9db691d747d579ebd9047e86aab26105b6bc3
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby/** @file
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * Incredibly Portable Runtime - ctype.h wrapper and C locale variants.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby/*
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * Copyright (C) 2006-2007 Sun Microsystems, Inc.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby *
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * This file is part of VirtualBox Open Source Edition (OSE), as
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * available from http://www.virtualbox.org. This file is free software;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * you can redistribute it and/or modify it under the terms of the GNU
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * General Public License (GPL) as published by the Free Software
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * Foundation, in version 2 as it comes in the "COPYING" file of the
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby *
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * The contents of this file may alternatively be used under the terms
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * of the Common Development and Distribution License Version 1.0
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * VirtualBox OSE distribution, in which case the provisions of the
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * CDDL are applicable instead of those of the GPL.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby *
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * You may elect to license modified versions of this file under the
2db6d663182655cb393dc2c15668bc9293364594Joshua M. Clulow * terms and conditions of either the GPL or the CDDL or both.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby *
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * Clara, CA 95054 USA or visit http://www.sun.com if you need
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * additional information or have any questions.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#ifndef ___iprt_ctype_h
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define ___iprt_ctype_h
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#ifdef IN_RING3
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# include <ctype.h>
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# if defined(_MSC_VER) && !defined(isblank)
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby/* isblank for MSC */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# define isblank(ch) ( (ch) == ' ' || (ch) == '\t' )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# endif
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#endif /* IN_RING3 */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby/** @name C locale macros.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby *
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * @remarks The macros may reference the character more than once.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * @remarks Assumes a charset similar to ASCII.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * @remarks Can probably be optimized if someone has time.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby * @{ */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_BLANK(ch) ( (ch) == ' ' || (ch) == '\t' )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_ALNUM(ch) ( RT_C_IS_DIGIT(ch) || RT_C_IS_ALPHA(ch) )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_ALPHA(ch) ( RT_C_IS_LOWER(ch) || RT_C_IS_UPPER(ch) )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_CNTRL(ch) ( (ch) >= 0 && (ch) < 32 )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_DIGIT(ch) ( (ch) >= '0' && (ch) <= '9' )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_LOWER(ch) ( (ch) >= 'a' && (ch) <= 'z' )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_GRAPH(ch) ( RT_C_IS_PRINT(ch) && !RT_C_IS_BLANK(ch) )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_ODIGIT(ch) ( (ch) >= '0' && (ch) <= '7' )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_PRINT(ch) ( (ch) >= 32 && (ch) < 127 ) /**< @todo possibly incorrect */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_PUNCT(ch) ( (ch) == ',' || (ch) == '.' || (ch) == ':' || (ch) == ';' || (ch) == '!' || (ch) == '?' ) /**< @todo possibly incorrect */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_SPACE(ch) ( (ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r' || (ch) == '\f' || (ch) == '\v' )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_UPPER(ch) ( (ch) >= 'A' && (ch) <= 'Z' )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_IS_XDIGIT(ch) ( RT_C_IS_DIGIT(ch) || ((ch) >= 'a' && (ch) <= 'f') || ((ch) >= 'A' && (ch) <= 'F') )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_TO_LOWER(ch) ( RT_C_IS_UPPER(ch) ? (ch) + ('a' - 'A') : (ch) )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#define RT_C_TO_UPPER(ch) ( RT_C_IS_LOWER(ch) ? (ch) - ('a' - 'A') : (ch) )
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby/** @} */
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#endif
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby