ctype.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* ctype.h
  2. * Character classification and conversion */
  3. #ifndef __CTYPE_H
  4. #define __CTYPE_H
  5. #include <features.h>
  6. /* For now, just always use the functions instead of the macros...*/
  7. #define __USE_CTYPE_C_FUNCTIONS
  8. /* Locale-compatible macros/inlines have yet to be implemented. */
  9. #if defined(__UCLIBC_HAS_LOCALE__) && !defined(__USE_CTYPE_C_FUNCTIONS)
  10. #define __USE_CTYPE_C_FUNCTIONS
  11. #endif
  12. #ifdef __USE_CTYPE_C_FUNCTIONS
  13. /* function prototpes */
  14. extern int isalnum(int c);
  15. extern int isalpha(int c);
  16. extern int isascii(int c);
  17. extern int iscntrl(int c);
  18. extern int isdigit(int c);
  19. extern int isgraph(int c);
  20. extern int islower(int c);
  21. extern int isprint(int c);
  22. extern int ispunct(int c);
  23. extern int isspace(int c);
  24. extern int isupper(int c);
  25. extern int isxdigit(int c);
  26. extern int isxlower(int c);
  27. extern int isxupper(int c);
  28. extern int toascii(int c);
  29. extern int tolower(int c);
  30. extern int toupper(int c);
  31. #else
  32. /* macro definitions */
  33. #define isalnum(c) (isalpha(c) || isdigit(c))
  34. #define isalpha(c) (isupper(c) || islower(c))
  35. #define isascii(c) (c > 0 && c <= 0x7f)
  36. #define iscntrl(c) ((c >= 0) && ((c <= 0x1F) || (c == 0x7f)))
  37. #define isdigit(c) (c >= '0' && c <= '9')
  38. #define isgraph(c) (c != ' ' && isprint(c))
  39. #define islower(c) (c >= 'a' && c <= 'z')
  40. #define isprint(c) (c >= ' ' && c <= '~')
  41. #define ispunct(c) ((c > ' ' && c <= '~') && !isalnum(c))
  42. #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' ||\
  43. c == '\t' || c == '\v')
  44. #define isupper(c) (c >= 'A' && c <= 'Z')
  45. #define isxdigit(c) (isxupper(c) || isxlower(c))
  46. #define isxlower(c) (isdigit(c) || (c >= 'a' && c <= 'f'))
  47. #define isxupper(c) (isdigit(c) || (c >= 'A' && c <= 'F'))
  48. #define toascii(c) (c & 0x7f)
  49. #define tolower(c) (isupper(c) ? ( c - 'A' + 'a') : (c))
  50. #define toupper(c) (islower(c) ? (c - 'a' + 'A') : (c))
  51. #endif
  52. #endif /* __CTYPE_H */