ctype.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* ctype.c
  2. * Character classification and conversion
  3. * Copyright (C) 2000 Lineo, Inc.
  4. * Written by Erik Andersen
  5. * This file is part of the uC-Libc C library and is distributed
  6. * under the GNU Library General Public License.
  7. */
  8. #include <ctype.h>
  9. int
  10. isalnum( int c )
  11. {
  12. return (isalpha(c) || isdigit(c));
  13. }
  14. int
  15. isalpha( int c )
  16. {
  17. return (isupper(c) || islower(c));
  18. }
  19. int
  20. isascii( int c )
  21. {
  22. return (c > 0 && c <= 0x7f);
  23. }
  24. int
  25. iscntrl( int c )
  26. {
  27. return ((c > 0) && ((c <= 0x1f) || (c == 0x7f)));
  28. }
  29. int
  30. isdigit( int c )
  31. {
  32. return (c >= '0' && c <= '9');
  33. }
  34. int
  35. isgraph( int c )
  36. {
  37. return (c != ' ' && isprint(c));
  38. }
  39. int
  40. islower( int c )
  41. {
  42. return (c >= 'a' && c <= 'z');
  43. }
  44. int
  45. isprint( int c )
  46. {
  47. return (c >= ' ' && c <= '~');
  48. }
  49. int
  50. ispunct( int c )
  51. {
  52. return ((c > ' ' && c <= '~') && !isalnum(c));
  53. }
  54. int
  55. isspace( int c )
  56. {
  57. return (c == ' ' || c == '\f' || c == '\n' || c == '\r' ||
  58. c == '\t' || c == '\v');
  59. }
  60. int
  61. isupper( int c )
  62. {
  63. return (c >= 'A' && c <= 'Z');
  64. }
  65. int
  66. isxdigit( int c )
  67. {
  68. return (isxupper(c) || isxlower(c));
  69. }
  70. int
  71. isxlower( int c )
  72. {
  73. return (isdigit(c) || (c >= 'a' && c <= 'f'));
  74. }
  75. int
  76. isxupper( int c )
  77. {
  78. return (isdigit(c) || (c >= 'A' && c <= 'F'));
  79. }
  80. int
  81. toascii( int c )
  82. {
  83. return (c & 0x7f);
  84. }
  85. int
  86. tolower( int c )
  87. {
  88. return (isupper(c) ? ( c - 'A' + 'a') : (c));
  89. }
  90. int
  91. toupper( int c )
  92. {
  93. return (islower(c) ? (c - 'a' + 'A') : (c));
  94. }