mod.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //! ctype implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/ctype.h.html
  2. use platform::types::*;
  3. #[no_mangle]
  4. pub extern "C" fn isalnum(c: c_int) -> c_int {
  5. (isdigit(c) != 0 || isalpha(c) != 0) as c_int
  6. }
  7. #[no_mangle]
  8. pub extern "C" fn isalpha(c: c_int) -> c_int {
  9. (islower(c) != 0 || isupper(c) != 0) as c_int
  10. }
  11. #[no_mangle]
  12. pub extern "C" fn isascii(c: c_int) -> c_int {
  13. ((c & !0x7f) == 0) as c_int
  14. }
  15. #[no_mangle]
  16. pub extern "C" fn isblank(c: c_int) -> c_int {
  17. (c == ' ' as c_int || c == '\t' as c_int) as c_int
  18. }
  19. #[no_mangle]
  20. pub extern "C" fn iscntrl(c: c_int) -> c_int {
  21. ((c as c_uint) < 0x20 || c == 0x7f) as c_int
  22. }
  23. #[no_mangle]
  24. pub extern "C" fn isdigit(c: c_int) -> c_int {
  25. (((c - 0x30) as c_uint) < 10) as c_int
  26. }
  27. #[no_mangle]
  28. pub extern "C" fn isgraph(c: c_int) -> c_int {
  29. (((c - 0x21) as c_uint) < 0x5e) as c_int
  30. }
  31. #[no_mangle]
  32. pub extern "C" fn islower(c: c_int) -> c_int {
  33. (((c - 0x61) as c_uint) < 26) as c_int
  34. }
  35. #[no_mangle]
  36. pub extern "C" fn isprint(c: c_int) -> c_int {
  37. (((c - 0x20) as c_uint) < 0x5f) as c_int
  38. }
  39. #[no_mangle]
  40. pub extern "C" fn ispunct(c: c_int) -> c_int {
  41. (isgraph(c) != 0 && !isalnum(c) != 0) as c_int
  42. }
  43. #[no_mangle]
  44. pub extern "C" fn isspace(c: c_int) -> c_int {
  45. (c == 0x20) as c_int
  46. }
  47. #[no_mangle]
  48. pub extern "C" fn isupper(c: c_int) -> c_int {
  49. (((c - 0x41) as c_uint) < 26) as c_int
  50. }
  51. #[no_mangle]
  52. pub extern "C" fn isxdigit(c: c_int) -> c_int {
  53. (isdigit(c) != 0 || ((c as c_int) | 32) - ('a' as c_int) < 6) as c_int
  54. }
  55. #[no_mangle]
  56. /// The comment in musl:
  57. /// "nonsense function that should NEVER be used!"
  58. pub extern "C" fn toascii(c: c_int) -> c_int {
  59. c & 0x7f
  60. }
  61. #[no_mangle]
  62. pub extern "C" fn tolower(c: c_int) -> c_int {
  63. if isupper(c) != 0 {
  64. c + 0x20
  65. } else {
  66. c
  67. }
  68. }
  69. #[no_mangle]
  70. pub extern "C" fn toupper(c: c_int) -> c_int {
  71. if islower(c) != 0 {
  72. c - 0x20
  73. } else {
  74. c
  75. }
  76. }