]> The Tcpdump Group git mirrors - tcpdump/blob - netdissect-ctype.h
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / netdissect-ctype.h
1 /*
2 * Copyright (c) 1988-1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Copyright (c) 1998-2012 Michael Richardson <mcr@tcpdump.org>
6 * The TCPDUMP project
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that: (1) source code distributions
10 * retain the above copyright notice and this paragraph in its entirety, (2)
11 * distributions including binary code include the above copyright notice and
12 * this paragraph in its entirety in the documentation or other materials
13 * provided with the distribution, and (3) all advertising materials mentioning
14 * features or use of this software display the following acknowledgement:
15 * ``This product includes software developed by the University of California,
16 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
17 * the University nor the names of its contributors may be used to endorse
18 * or promote products derived from this software without specific prior
19 * written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 */
24
25 #ifndef netdissect_ctype_h
26 #define netdissect_ctype_h
27
28 /*
29 * Locale-independent macros for testing character properties and
30 * stripping the 8th bit from characters.
31 *
32 * Byte values outside the ASCII range are considered unprintable, so
33 * both ND_ASCII_ISPRINT() and ND_ASCII_ISGRAPH() return "false" for them.
34 *
35 * Assumed to be handed a value between 0 and 255, i.e. don't hand them
36 * a char, as those might be in the range -128 to 127.
37 */
38 #define ND_ISASCII(c) (!((c) & 0x80)) /* value is an ASCII code point */
39 #define ND_ASCII_ISPRINT(c) ((c) >= 0x20 && (c) <= 0x7E)
40 #define ND_ASCII_ISGRAPH(c) ((c) > 0x20 && (c) <= 0x7E)
41 #define ND_ASCII_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
42 #define ND_TOASCII(c) ((c) & 0x7F)
43
44 /*
45 * Locale-independent macros for converting to upper or lower case.
46 *
47 * Byte values outside the ASCII range are not converted. Byte values
48 * *in* the ASCII range are converted to byte values in the ASCII range;
49 * in particular, 'i' is upper-cased to 'I" and 'I' is lower-cased to 'i',
50 * even in Turkish locales.
51 */
52 #define ND_ASCII_TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
53 #define ND_ASCII_TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'A' : (c))
54
55 #endif /* netdissect-ctype.h */
56