2021-05-16 18:09:40 +02:00
|
|
|
#ifndef __CTYPE_H__
|
|
|
|
# define __CTYPE_H__
|
|
|
|
|
2021-06-28 15:49:05 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-05-16 18:09:40 +02:00
|
|
|
/*
|
|
|
|
** Character classification functions. These are all implemented as sets of
|
|
|
|
** comparisons. There is an approach with a 128-byte table, but it takes more
|
2021-05-18 11:37:37 +02:00
|
|
|
** space; in fact, every function but isalnum, ispunct and isxdigit needs less
|
|
|
|
** code to compare than to perform the lookup. Additionally, users won't need
|
|
|
|
** the whole table for a single call to isspace().
|
2021-05-16 18:09:40 +02:00
|
|
|
*/
|
|
|
|
extern int isalnum(int c);
|
|
|
|
extern int isalpha(int c);
|
|
|
|
extern int isblank(int c);
|
|
|
|
extern int iscntrl(int c);
|
|
|
|
extern int isdigit(int c);
|
|
|
|
extern int isgraph(int c);
|
|
|
|
extern int islower(int c);
|
|
|
|
extern int isprint(int c);
|
|
|
|
extern int ispunct(int c);
|
|
|
|
extern int isspace(int c);
|
|
|
|
extern int isupper(int c);
|
|
|
|
extern int isxdigit(int c);
|
|
|
|
|
|
|
|
/* Case conversion functions */
|
|
|
|
extern int tolower(int c);
|
|
|
|
extern int toupper(int c);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Macro versions; these functions are very fast so it's worth it to inline
|
|
|
|
** them rather than perform a function call as expensive as the test. These are
|
|
|
|
** valid in the "C" locale, the only one supported by this library.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define isalnum(c) ({ \
|
2021-05-18 11:37:37 +02:00
|
|
|
int __c0 = (c); \
|
|
|
|
isalpha(__c0) || isdigit(__c0); \
|
2021-05-16 18:09:40 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
#define isalpha(c) ({ \
|
|
|
|
int __c = (c) | 0x20; \
|
|
|
|
(__c >= 'a') && (__c <= 'z'); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define isblank(c) ({ \
|
|
|
|
int __c = (c); \
|
|
|
|
(__c == 9) || (__c == 32); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define iscntrl(c) ({ \
|
|
|
|
int __c = (c); \
|
|
|
|
(__c < 32) || (__c >= 0x7f); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define isdigit(c) ({ \
|
|
|
|
int __c = (c); \
|
|
|
|
(__c >= '0') && (__c <= '9'); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define isgraph(c) ({ \
|
|
|
|
int __c = (c); \
|
|
|
|
(__c >= 33) && (__c < 0x7f); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define islower(c) ({ \
|
|
|
|
int __c = (c); \
|
|
|
|
(__c >= 'a') && (__c <= 'z'); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define isprint(c) ({ \
|
|
|
|
int __c = (c); \
|
2021-05-18 11:37:37 +02:00
|
|
|
(__c >= 32) && (__c < 0x7f); \
|
2021-05-16 18:09:40 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
#define ispunct(c) ({ \
|
|
|
|
int __c = (c); \
|
|
|
|
(__c >= 33 && __c <= 47) || (__c >= 58 && __c <= 64) || \
|
|
|
|
(__c >= 91 && __c <= 96) || (__c >= 123 && __c <= 126); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define isspace(c) ({ \
|
|
|
|
int __c = (c); \
|
|
|
|
(__c >= 9 && __c <= 13) || (__c == 32); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define isupper(c) ({ \
|
|
|
|
int __c = (c); \
|
|
|
|
(__c >= 'A') && (__c <= 'Z'); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define isxdigit(c) ({ \
|
|
|
|
int __c = (c); \
|
|
|
|
int __c20 = __c | 0x20; \
|
2021-05-18 11:37:37 +02:00
|
|
|
(__c >= '0' && __c <= '9') || (__c20 >= 'a' && __c20 <= 'f'); \
|
2021-05-16 18:09:40 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
#define tolower(c) ({ \
|
2021-05-18 11:51:49 +02:00
|
|
|
int __c0 = (c); \
|
|
|
|
isupper(__c0) ? (__c0 | 0x20) : __c0; \
|
2021-05-16 18:09:40 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
#define toupper(c) ({ \
|
2021-05-18 11:51:49 +02:00
|
|
|
int __c0 = (c); \
|
|
|
|
islower(__c0) ? (__c0 & 0xdf) : __c0; \
|
2021-05-16 18:09:40 +02:00
|
|
|
})
|
|
|
|
|
2021-06-28 15:49:05 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-05-16 18:09:40 +02:00
|
|
|
#endif /*__CTYPE_H__*/
|