ctype.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /**
  3. ******************************************************************************
  4. * @file ctype.h
  5. * @author StarFive Technology
  6. * @version V1.0
  7. * @date 07/29/2020
  8. * @brief
  9. ******************************************************************************
  10. * @copy
  11. *
  12. * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STARFIVE SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * COPYRIGHT 20120 Shanghai StarFive Technology Co., Ltd.
  20. */
  21. #ifndef _CTYPE_H
  22. #define _CTYPE_H
  23. /*
  24. * NOTE! This ctype does not handle EOF like the standard C
  25. * library is required to.
  26. */
  27. #define _U 0x01 /* upper */
  28. #define _L 0x02 /* lower */
  29. #define _D 0x04 /* digit */
  30. #define _C 0x08 /* cntrl */
  31. #define _P 0x10 /* punct */
  32. #define _S 0x20 /* white space (space/lf/tab) */
  33. #define _X 0x40 /* hex digit */
  34. #define _SP 0x80 /* hard space (0x20) */
  35. extern const unsigned char _ctype[];
  36. #define __ismask(x) (_ctype[(int)(unsigned char)(x)])
  37. #define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
  38. #define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
  39. #define iscntrl(c) ((__ismask(c)&(_C)) != 0)
  40. static inline int isdigit(int c)
  41. {
  42. return '0' <= c && c <= '9';
  43. }
  44. #define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
  45. #define islower(c) ((__ismask(c)&(_L)) != 0)
  46. #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
  47. #define ispunct(c) ((__ismask(c)&(_P)) != 0)
  48. #define isspace(c) ((__ismask(c)&(_S)) != 0)
  49. #define isupper(c) ((__ismask(c)&(_U)) != 0)
  50. #define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
  51. #define isascii(c) (((unsigned char)(c))<=0x7f)
  52. #define toascii(c) (((unsigned char)(c))&0x7f)
  53. static inline unsigned char __tolower(unsigned char c)
  54. {
  55. if (isupper(c))
  56. c -= 'A'-'a';
  57. return c;
  58. }
  59. static inline unsigned char __toupper(unsigned char c)
  60. {
  61. if (islower(c))
  62. c -= 'a'-'A';
  63. return c;
  64. }
  65. #define tolower(c) __tolower(c)
  66. #define toupper(c) __toupper(c)
  67. /*
  68. * Fast implementation of tolower() for internal usage. Do not use in your
  69. * code.
  70. */
  71. static inline char _tolower(const char c)
  72. {
  73. return c | 0x20;
  74. }
  75. /* Fast check for octal digit */
  76. static inline int isodigit(const char c)
  77. {
  78. return c >= '0' && c <= '7';
  79. }
  80. #endif