ctype.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /*
  10. * This version of ctype.h provides a standardised and platform
  11. * independent implementation that supports seven bit ASCII characters.
  12. * The specific intent is to not pass extended ASCII characters (> 127)
  13. * even if the host operating system would.
  14. *
  15. * There is EBCDIC support included for machines which use this. However,
  16. * there are a number of concerns about how well EBCDIC is supported
  17. * throughout the rest of the source code. Refer to issue #4154 for
  18. * details.
  19. */
  20. #ifndef INTERNAL_CTYPE_H
  21. # define INTERNAL_CTYPE_H
  22. # define CTYPE_MASK_lower 0x1
  23. # define CTYPE_MASK_upper 0x2
  24. # define CTYPE_MASK_digit 0x4
  25. # define CTYPE_MASK_space 0x8
  26. # define CTYPE_MASK_xdigit 0x10
  27. # define CTYPE_MASK_blank 0x20
  28. # define CTYPE_MASK_cntrl 0x40
  29. # define CTYPE_MASK_graph 0x80
  30. # define CTYPE_MASK_print 0x100
  31. # define CTYPE_MASK_punct 0x200
  32. # define CTYPE_MASK_base64 0x400
  33. # define CTYPE_MASK_asn1print 0x800
  34. # define CTYPE_MASK_alpha (CTYPE_MASK_lower | CTYPE_MASK_upper)
  35. # define CTYPE_MASK_alnum (CTYPE_MASK_alpha | CTYPE_MASK_digit)
  36. /*
  37. * The ascii mask assumes that any other classification implies that
  38. * the character is ASCII and that there are no ASCII characters
  39. * that aren't in any of the classifications.
  40. *
  41. * This assumption holds at the moment, but it might not in the future.
  42. */
  43. # define CTYPE_MASK_ascii (~0)
  44. # ifdef CHARSET_EBCDIC
  45. int ossl_toascii(int c);
  46. int ossl_fromascii(int c);
  47. # else
  48. # define ossl_toascii(c) (c)
  49. # define ossl_fromascii(c) (c)
  50. # endif
  51. int ossl_ctype_check(int c, unsigned int mask);
  52. int ossl_tolower(int c);
  53. int ossl_toupper(int c);
  54. # define ossl_isalnum(c) (ossl_ctype_check((c), CTYPE_MASK_alnum))
  55. # define ossl_isalpha(c) (ossl_ctype_check((c), CTYPE_MASK_alpha))
  56. # ifdef CHARSET_EBCDIC
  57. # define ossl_isascii(c) (ossl_ctype_check((c), CTYPE_MASK_ascii))
  58. # else
  59. # define ossl_isascii(c) (((c) & ~127) == 0)
  60. # endif
  61. # define ossl_isblank(c) (ossl_ctype_check((c), CTYPE_MASK_blank))
  62. # define ossl_iscntrl(c) (ossl_ctype_check((c), CTYPE_MASK_cntrl))
  63. # define ossl_isdigit(c) (ossl_ctype_check((c), CTYPE_MASK_digit))
  64. # define ossl_isgraph(c) (ossl_ctype_check((c), CTYPE_MASK_graph))
  65. # define ossl_islower(c) (ossl_ctype_check((c), CTYPE_MASK_lower))
  66. # define ossl_isprint(c) (ossl_ctype_check((c), CTYPE_MASK_print))
  67. # define ossl_ispunct(c) (ossl_ctype_check((c), CTYPE_MASK_punct))
  68. # define ossl_isspace(c) (ossl_ctype_check((c), CTYPE_MASK_space))
  69. # define ossl_isupper(c) (ossl_ctype_check((c), CTYPE_MASK_upper))
  70. # define ossl_isxdigit(c) (ossl_ctype_check((c), CTYPE_MASK_xdigit))
  71. # define ossl_isbase64(c) (ossl_ctype_check((c), CTYPE_MASK_base64))
  72. # define ossl_isasn1print(c) (ossl_ctype_check((c), CTYPE_MASK_asn1print))
  73. #endif