Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
0002 /*
0003  * ctype function definitions for NOLIBC
0004  * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
0005  */
0006 
0007 #ifndef _NOLIBC_CTYPE_H
0008 #define _NOLIBC_CTYPE_H
0009 
0010 #include "std.h"
0011 
0012 /*
0013  * As much as possible, please keep functions alphabetically sorted.
0014  */
0015 
0016 static __attribute__((unused))
0017 int isascii(int c)
0018 {
0019     /* 0x00..0x7f */
0020     return (unsigned int)c <= 0x7f;
0021 }
0022 
0023 static __attribute__((unused))
0024 int isblank(int c)
0025 {
0026     return c == '\t' || c == ' ';
0027 }
0028 
0029 static __attribute__((unused))
0030 int iscntrl(int c)
0031 {
0032     /* 0x00..0x1f, 0x7f */
0033     return (unsigned int)c < 0x20 || c == 0x7f;
0034 }
0035 
0036 static __attribute__((unused))
0037 int isdigit(int c)
0038 {
0039     return (unsigned int)(c - '0') < 10;
0040 }
0041 
0042 static __attribute__((unused))
0043 int isgraph(int c)
0044 {
0045     /* 0x21..0x7e */
0046     return (unsigned int)(c - 0x21) < 0x5e;
0047 }
0048 
0049 static __attribute__((unused))
0050 int islower(int c)
0051 {
0052     return (unsigned int)(c - 'a') < 26;
0053 }
0054 
0055 static __attribute__((unused))
0056 int isprint(int c)
0057 {
0058     /* 0x20..0x7e */
0059     return (unsigned int)(c - 0x20) < 0x5f;
0060 }
0061 
0062 static __attribute__((unused))
0063 int isspace(int c)
0064 {
0065     /* \t is 0x9, \n is 0xA, \v is 0xB, \f is 0xC, \r is 0xD */
0066     return ((unsigned int)c == ' ') || (unsigned int)(c - 0x09) < 5;
0067 }
0068 
0069 static __attribute__((unused))
0070 int isupper(int c)
0071 {
0072     return (unsigned int)(c - 'A') < 26;
0073 }
0074 
0075 static __attribute__((unused))
0076 int isxdigit(int c)
0077 {
0078     return isdigit(c) || (unsigned int)(c - 'A') < 6 || (unsigned int)(c - 'a') < 6;
0079 }
0080 
0081 static __attribute__((unused))
0082 int isalpha(int c)
0083 {
0084     return islower(c) || isupper(c);
0085 }
0086 
0087 static __attribute__((unused))
0088 int isalnum(int c)
0089 {
0090     return isalpha(c) || isdigit(c);
0091 }
0092 
0093 static __attribute__((unused))
0094 int ispunct(int c)
0095 {
0096     return isgraph(c) && !isalnum(c);
0097 }
0098 
0099 #endif /* _NOLIBC_CTYPE_H */