You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ctype.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef _CTYPE_H
  2. #define _CTYPE_H
  3. /** @file
  4. *
  5. * Character types
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. /**
  10. * Check if character is a decimal digit
  11. *
  12. * @v character ASCII character
  13. * @ret is_digit Character is a decimal digit
  14. */
  15. static inline int isdigit ( int character ) {
  16. return ( ( character >= '0' ) && ( character <= '9' ) );
  17. }
  18. /**
  19. * Check if character is a hexadecimal digit
  20. *
  21. * @v character ASCII character
  22. * @ret is_xdigit Character is a hexadecimal digit
  23. */
  24. static inline int isxdigit ( int character ) {
  25. return ( ( ( character >= '0' ) && ( character <= '9' ) ) ||
  26. ( ( character >= 'A' ) && ( character <= 'F' ) ) ||
  27. ( ( character >= 'a' ) && ( character <= 'f' ) ) );
  28. }
  29. /**
  30. * Check if character is an upper-case letter
  31. *
  32. * @v character ASCII character
  33. * @ret is_upper Character is an upper-case letter
  34. */
  35. static inline int isupper ( int character ) {
  36. return ( ( character >= 'A' ) && ( character <= 'Z' ) );
  37. }
  38. /**
  39. * Check if character is a lower-case letter
  40. *
  41. * @v character ASCII character
  42. * @ret is_lower Character is a lower-case letter
  43. */
  44. static inline int islower ( int character ) {
  45. return ( ( character >= 'a' ) && ( character <= 'z' ) );
  46. }
  47. /**
  48. * Check if character is alphabetic
  49. *
  50. * @v character ASCII character
  51. * @ret is_alpha Character is alphabetic
  52. */
  53. static inline int isalpha ( int character ) {
  54. return ( isupper ( character ) || islower ( character ) );
  55. }
  56. /**
  57. * Check if character is alphanumeric
  58. *
  59. * @v character ASCII character
  60. * @ret is_alnum Character is alphanumeric
  61. */
  62. static inline int isalnum ( int character ) {
  63. return ( isalpha ( character ) || isdigit ( character ) );
  64. }
  65. /**
  66. * Check if character is printable
  67. *
  68. * @v character ASCII character
  69. * @ret is_print Character is printable
  70. */
  71. static inline int isprint ( int character ) {
  72. return ( ( character >= ' ' ) && ( character <= '~' ) );
  73. }
  74. /**
  75. * Convert character to lower case
  76. *
  77. * @v character Character
  78. * @v character Lower-case character
  79. */
  80. static inline int tolower ( int character ) {
  81. return ( isupper ( character ) ?
  82. ( character - 'A' + 'a' ) : character );
  83. }
  84. /**
  85. * Convert character to upper case
  86. *
  87. * @v character Character
  88. * @v character Upper-case character
  89. */
  90. static inline int toupper ( int character ) {
  91. return ( islower ( character ) ?
  92. ( character - 'a' + 'A' ) : character );
  93. }
  94. extern int isspace ( int character );
  95. #endif /* _CTYPE_H */