This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/os/pl-ctype.h

84 lines
3.4 KiB
C
Raw Normal View History

2013-11-15 01:10:25 +00:00
/* Part of SWI-Prolog
2008-12-22 12:02:22 +00:00
Author: Jan Wielemaker
2013-11-15 01:10:25 +00:00
E-mail: J.Wielemaker@vu.nl
2008-12-22 12:02:22 +00:00
WWW: http://www.swi-prolog.org
2013-11-15 01:10:25 +00:00
Copyright (C): 1985-2013, University of Amsterdam
VU University Amsterdam
2008-12-22 12:02:22 +00:00
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
2012-02-01 20:52:13 +00:00
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2008-12-22 12:02:22 +00:00
*/
extern const char _PL_char_types[]; /* array of character types */
#define CT 0 /* control-character */
#define SP 1 /* space */
#define SO 2 /* solo character */
#define SY 3 /* symbol character */
#define PU 4 /* Punctuation character */
#define DQ 5 /* Double quote */
#define SQ 6 /* Single quote */
#define BQ 7 /* Back quote */
#define UC 8 /* Uppercase character */
#define LC 9 /* Lowercase character */
#define DI 10 /* Digit */
#define isControl(c) (_PL_char_types[(unsigned)(c) & 0xff] == CT)
2012-02-01 20:52:13 +00:00
#define isBlank(c) (_PL_char_types[(unsigned)(c) & 0xff] == SP)
#define isGraph(c) (_PL_char_types[(unsigned)(c) & 0xff] > SP)
2008-12-22 12:02:22 +00:00
#define isDigit(c) (_PL_char_types[(unsigned)(c) & 0xff] == DI)
#define isLower(c) (_PL_char_types[(unsigned)(c) & 0xff] == LC)
#define isUpper(c) (_PL_char_types[(unsigned)(c) & 0xff] == UC)
#define isSymbol(c) (_PL_char_types[(unsigned)(c) & 0xff] == SY)
#define isPunct(c) (_PL_char_types[(unsigned)(c) & 0xff] == PU)
#define isSolo(c) (_PL_char_types[(unsigned)(c) & 0xff] == SO)
#define isAlpha(c) (_PL_char_types[(unsigned)(c) & 0xff] >= UC)
#define isLetter(c) (isLower(c) || isUpper(c))
2011-02-10 00:01:19 +00:00
#define isSign(c) ((c) == '-' || (c) == '+')
2008-12-22 12:02:22 +00:00
#define toLower(c) ((c) + 'a' - 'A')
#define makeLower(c) ((c) >= 'A' && (c) <= 'Z' ? toLower(c) : (c))
#define matchingBracket(c) ((c) == '[' ? ']' :\
2013-11-15 01:10:25 +00:00
(c) == '{' ? '}' :\
(c) == '(' ? ')' : EOS)
2008-12-22 12:02:22 +00:00
#define Control(c) ((c) == '?' ? 127 : (c) - '@')
/*******************************
* WIDE CHARACTER SUPPORT *
*******************************/
#include <wctype.h>
#include <wchar.h>
#define PlCharType(c, t, w) \
((unsigned)(c) <= 0xff ? (_PL_char_types[(unsigned char)(c)] t) : w)
#define isControlW(c) PlCharType(c, == CT, iswcntrl((wint_t)c))
2012-02-01 20:52:13 +00:00
#define isBlankW(c) PlCharType(c, == SP, iswspace((wint_t)c))
2008-12-22 12:02:22 +00:00
#define isDigitW(c) PlCharType(c, == DI, FALSE)
#define isLowerW(c) PlCharType(c, == LC, iswlower((wint_t)c))
#define isUpperW(c) PlCharType(c, == UC, iswupper((wint_t)c))
#define isSymbolW(c) PlCharType(c, == SY, FALSE)
#define isPunctW(c) PlCharType(c, == PU, FALSE)
#define isSoloW(c) PlCharType(c, == SO, FALSE)
#define isAlphaW(c) PlCharType(c, >= UC, iswalnum((wint_t)c))
#define isLetterW(c) (PlCharType(c, == LC, iswalpha((wint_t)c)) || \
PlCharType(c, == UC, FALSE))
#define toLowerW(c) ((unsigned)(c) <= 'Z' ? (c) + 'a' - 'A' : towlower(c))
#define makeLowerW(c) ((c) >= 'A' && (c) <= 'Z' ? toLower(c) : towlower(c))