ctype.h 2.4 KB

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