curl_ctype.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "curl_setup.h"
  23. #ifndef CURL_DOES_CONVERSIONS
  24. #undef _U
  25. #define _U (1<<0) /* upper case */
  26. #undef _L
  27. #define _L (1<<1) /* lower case */
  28. #undef _N
  29. #define _N (1<<2) /* decimal numerical digit */
  30. #undef _S
  31. #define _S (1<<3) /* space */
  32. #undef _P
  33. #define _P (1<<4) /* punctuation */
  34. #undef _C
  35. #define _C (1<<5) /* control */
  36. #undef _X
  37. #define _X (1<<6) /* hexadecimal letter */
  38. #undef _B
  39. #define _B (1<<7) /* blank */
  40. static const unsigned char ascii[128] = {
  41. _C, _C, _C, _C, _C, _C, _C, _C,
  42. _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C,
  43. _C, _C, _C, _C, _C, _C, _C, _C,
  44. _C, _C, _C, _C, _C, _C, _C, _C,
  45. _S|_B, _P, _P, _P, _P, _P, _P, _P,
  46. _P, _P, _P, _P, _P, _P, _P, _P,
  47. _N, _N, _N, _N, _N, _N, _N, _N,
  48. _N, _N, _P, _P, _P, _P, _P, _P,
  49. _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U,
  50. _U, _U, _U, _U, _U, _U, _U, _U,
  51. _U, _U, _U, _U, _U, _U, _U, _U,
  52. _U, _U, _U, _P, _P, _P, _P, _P,
  53. _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L,
  54. _L, _L, _L, _L, _L, _L, _L, _L,
  55. _L, _L, _L, _L, _L, _L, _L, _L,
  56. _L, _L, _L, _P, _P, _P, _P, _C
  57. };
  58. int Curl_isspace(int c)
  59. {
  60. if((c < 0) || (c >= 0x80))
  61. return FALSE;
  62. return (ascii[c] & _S);
  63. }
  64. int Curl_isdigit(int c)
  65. {
  66. if((c < 0) || (c >= 0x80))
  67. return FALSE;
  68. return (ascii[c] & _N);
  69. }
  70. int Curl_isalnum(int c)
  71. {
  72. if((c < 0) || (c >= 0x80))
  73. return FALSE;
  74. return (ascii[c] & (_N|_U|_L));
  75. }
  76. int Curl_isxdigit(int c)
  77. {
  78. if((c < 0) || (c >= 0x80))
  79. return FALSE;
  80. return (ascii[c] & (_N|_X));
  81. }
  82. int Curl_isgraph(int c)
  83. {
  84. if((c < 0) || (c >= 0x80) || (c == ' '))
  85. return FALSE;
  86. return (ascii[c] & (_N|_X|_U|_L|_P|_S));
  87. }
  88. int Curl_isprint(int c)
  89. {
  90. if((c < 0) || (c >= 0x80))
  91. return FALSE;
  92. return (ascii[c] & (_N|_X|_U|_L|_P|_S));
  93. }
  94. int Curl_isalpha(int c)
  95. {
  96. if((c < 0) || (c >= 0x80))
  97. return FALSE;
  98. return (ascii[c] & (_U|_L));
  99. }
  100. int Curl_isupper(int c)
  101. {
  102. if((c < 0) || (c >= 0x80))
  103. return FALSE;
  104. return (ascii[c] & (_U));
  105. }
  106. int Curl_islower(int c)
  107. {
  108. if((c < 0) || (c >= 0x80))
  109. return FALSE;
  110. return (ascii[c] & (_L));
  111. }
  112. int Curl_iscntrl(int c)
  113. {
  114. if((c < 0) || (c >= 0x80))
  115. return FALSE;
  116. return (ascii[c] & (_C));
  117. }
  118. #endif /* !CURL_DOES_CONVERSIONS */