ctype.h 1.9 KB

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