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. // isdigit() man says that argument must be unsigned char
  22. return isdigit((unsigned char)c) ? BOOL_TRUE : BOOL_FALSE;
  23. }
  24. /** @brief Checks for a white space
  25. *
  26. * The function is same as standard isspace() but gets char type
  27. * as an argument.
  28. *
  29. * @param [in] c Character to classify.
  30. * @return BOOL_TRUE if char is space and BOOL_FALSE else.
  31. */
  32. bool_t faux_ctype_isspace(char c) {
  33. // isspace() man says that argument must be unsigned char
  34. return isspace((unsigned char)c) ? BOOL_TRUE : BOOL_FALSE;
  35. }
  36. /** @brief Converts uppercase characters to lowercase
  37. *
  38. * The function is same as standard tolower() but gets char type
  39. * as an argument.
  40. *
  41. * @param [in] c Character to convert.
  42. * @return Converted character.
  43. */
  44. char faux_ctype_tolower(char c) {
  45. // tolower() man says that argument must be unsigned char
  46. return tolower((unsigned char)c);
  47. }
  48. /** @brief Converts lowercase characters to uppercase
  49. *
  50. * The function is same as standard toupper() but gets char type
  51. * as an argument.
  52. *
  53. * @param [in] c Character to convert.
  54. * @return Converted character.
  55. */
  56. char faux_ctype_toupper(char c)
  57. {
  58. // toupper() man says that argument must be unsigned char
  59. return toupper((unsigned char)c);
  60. }