ctype.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /** @file ctype.c
  2. * @brief The ctype functions
  3. *
  4. * Some ctype functions are not compatible among different OSes.
  5. * So faux library functions use their own versions of some
  6. * ctype functions to unify the behaviour. Really for now all
  7. * faux ctype functions are only a wrappers for standard functions.
  8. * But it can be changed in future for portability purposes.
  9. */
  10. #include <ctype.h>
  11. #include "faux/ctype.h"
  12. /** @brief Checks for a digit
  13. *
  14. * The function is same as standard isdigit() but gets char type
  15. * as an argument.
  16. *
  17. * @param [in] c Character to classify.
  18. * @return BOOL_TRUE if char is digit and BOOL_FALSE else.
  19. */
  20. bool_t faux_ctype_isdigit(char c)
  21. {
  22. // isdigit() man says that argument must be unsigned char
  23. return isdigit((unsigned char)c) ? BOOL_TRUE : BOOL_FALSE;
  24. }
  25. /** @brief Checks for a white space
  26. *
  27. * The function is same as standard isspace() but gets char type
  28. * as an argument.
  29. *
  30. * @param [in] c Character to classify.
  31. * @return BOOL_TRUE if char is space and BOOL_FALSE else.
  32. */
  33. bool_t faux_ctype_isspace(char c)
  34. {
  35. // isspace() man says that argument must be unsigned char
  36. return isspace((unsigned char)c) ? BOOL_TRUE : BOOL_FALSE;
  37. }
  38. /** @brief Converts uppercase characters to lowercase
  39. *
  40. * The function is same as standard tolower() but gets char type
  41. * as an argument.
  42. *
  43. * @param [in] c Character to convert.
  44. * @return Converted character.
  45. */
  46. char faux_ctype_tolower(char c)
  47. {
  48. // tolower() man says that argument must be unsigned char
  49. return tolower((unsigned char)c);
  50. }
  51. /** @brief Converts lowercase characters to uppercase
  52. *
  53. * The function is same as standard toupper() but gets char type
  54. * as an argument.
  55. *
  56. * @param [in] c Character to convert.
  57. * @return Converted character.
  58. */
  59. char faux_ctype_toupper(char c)
  60. {
  61. // toupper() man says that argument must be unsigned char
  62. return toupper((unsigned char)c);
  63. }