]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/safe-ctype.c
* doc/rtl.texi: Fix the @findex for pre_modify.
[thirdparty/gcc.git] / libiberty / safe-ctype.c
CommitLineData
f6bbde28
ZW
1/* <ctype.h> replacement macros.
2
3 Copyright (C) 2000 Free Software Foundation, Inc.
4 Contributed by Zack Weinberg <zackw@stanford.edu>.
5
6This file is part of the libiberty library.
7Libiberty is free software; you can redistribute it and/or
8modify it under the terms of the GNU Library General Public
9License as published by the Free Software Foundation; either
10version 2 of the License, or (at your option) any later version.
11
12Libiberty is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Library General Public License for more details.
16
17You should have received a copy of the GNU Library General Public
18License along with libiberty; see the file COPYING.LIB. If
19not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22/* This is a compatible replacement of the standard C library's <ctype.h>
23 with the following properties:
24
25 - Implements all isxxx() macros required by C99.
26 - Also implements some character classes useful when
27 parsing C-like languages.
28 - Does not change behavior depending on the current locale.
29 - Behaves properly for all values in the range of a signed or
30 unsigned char. */
31
a8e4a997 32#include "ansidecl.h"
f6bbde28
ZW
33#include <safe-ctype.h>
34#include <stdio.h> /* for EOF */
35
7468e0b5
ZW
36#if EOF != -1
37 #error "<safe-ctype.h> requires EOF == -1"
38#endif
39
f6bbde28
ZW
40/* Shorthand */
41#define bl _sch_isblank
42#define cn _sch_iscntrl
43#define di _sch_isdigit
44#define is _sch_isidst
45#define lo _sch_islower
46#define nv _sch_isnvsp
47#define pn _sch_ispunct
48#define pr _sch_isprint
49#define sp _sch_isspace
50#define up _sch_isupper
51#define vs _sch_isvsp
52#define xd _sch_isxdigit
53
54/* Masks. */
f08b7eee
JDA
55#define L (const unsigned short) (lo|is |pr) /* lower case letter */
56#define XL (const unsigned short) (lo|is|xd|pr) /* lowercase hex digit */
57#define U (const unsigned short) (up|is |pr) /* upper case letter */
58#define XU (const unsigned short) (up|is|xd|pr) /* uppercase hex digit */
59#define D (const unsigned short) (di |xd|pr) /* decimal digit */
60#define P (const unsigned short) (pn |pr) /* punctuation */
61#define _ (const unsigned short) (pn|is |pr) /* underscore */
f6bbde28 62
f08b7eee
JDA
63#define C (const unsigned short) ( cn) /* control character */
64#define Z (const unsigned short) (nv |cn) /* NUL */
65#define M (const unsigned short) (nv|sp |cn) /* cursor movement: \f \v */
66#define V (const unsigned short) (vs|sp |cn) /* vertical space: \r \n */
67#define T (const unsigned short) (nv|sp|bl|cn) /* tab */
68#define S (const unsigned short) (nv|sp|bl|pr) /* space */
f6bbde28
ZW
69
70/* Are we ASCII? */
7468e0b5 71#if HOST_CHARSET == HC_ASCII
f6bbde28
ZW
72
73const unsigned short _sch_istable[256] =
74{
75 Z, C, C, C, C, C, C, C, /* NUL SOH STX ETX EOT ENQ ACK BEL */
76 C, T, V, M, M, V, C, C, /* BS HT LF VT FF CR SO SI */
77 C, C, C, C, C, C, C, C, /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB */
78 C, C, C, C, C, C, C, C, /* CAN EM SUB ESC FS GS RS US */
79 S, P, P, P, P, P, P, P, /* SP ! " # $ % & ' */
80 P, P, P, P, P, P, P, P, /* ( ) * + , - . / */
81 D, D, D, D, D, D, D, D, /* 0 1 2 3 4 5 6 7 */
82 D, D, P, P, P, P, P, P, /* 8 9 : ; < = > ? */
83 P, XU, XU, XU, XU, XU, XU, U, /* @ A B C D E F G */
84 U, U, U, U, U, U, U, U, /* H I J K L M N O */
85 U, U, U, U, U, U, U, U, /* P Q R S T U V W */
86 U, U, U, P, P, P, P, _, /* X Y Z [ \ ] ^ _ */
87 P, XL, XL, XL, XL, XL, XL, L, /* ` a b c d e f g */
88 L, L, L, L, L, L, L, L, /* h i j k l m n o */
89 L, L, L, L, L, L, L, L, /* p q r s t u v w */
90 L, L, L, P, P, P, P, C, /* x y z { | } ~ DEL */
91
92 /* high half of unsigned char is locale-specific, so all tests are
93 false in "C" locale */
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103};
104
105const unsigned char _sch_tolower[256] =
106{
107 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
108 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
109 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
110 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
111 64,
112
113 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
114 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
115
116 91, 92, 93, 94, 95, 96,
117
118 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
119 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
120
121 123,124,125,126,127,
122
123 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
124 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
125 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
126 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
127
128 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
129 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
130 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
131 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
132};
133
134const unsigned char _sch_toupper[256] =
135{
136 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
137 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
138 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
139 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
140 64,
141
142 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
143 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
144
145 91, 92, 93, 94, 95, 96,
146
147 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
148 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
149
150 123,124,125,126,127,
151
152 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
153 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
154 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
155 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
156
157 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
158 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
159 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
160 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
161};
162
163#else
7468e0b5
ZW
164# if HOST_CHARSET == HC_EBCDIC
165 #error "FIXME: write tables for EBCDIC"
166# else
167 #error "Unrecognized host character set"
168# endif
169#endif