mod.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //! wchar implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/wctype.h.html
  2. use crate::{
  3. c_str::CStr,
  4. platform::types::*,
  5. };
  6. mod casecmp;
  7. use casecmp::casemap;
  8. pub const WEOF: wint_t = 0xFFFF_FFFFu32;
  9. pub const WCTYPE_ALNUM: wctype_t = 1;
  10. pub const WCTYPE_ALPHA: wctype_t = 2;
  11. pub const WCTYPE_BLANK: wctype_t = 3;
  12. pub const WCTYPE_CNTRL: wctype_t = 4;
  13. pub const WCTYPE_DIGIT: wctype_t = 5;
  14. pub const WCTYPE_GRAPH: wctype_t = 6;
  15. pub const WCTYPE_LOWER: wctype_t = 7;
  16. pub const WCTYPE_PRINT: wctype_t = 8;
  17. pub const WCTYPE_PUNCT: wctype_t = 9;
  18. pub const WCTYPE_SPACE: wctype_t = 10;
  19. pub const WCTYPE_UPPER: wctype_t = 11;
  20. pub const WCTYPE_XDIGIT: wctype_t = 12;
  21. #[no_mangle]
  22. pub unsafe extern "C" fn wctype(name: *const c_char) -> wctype_t {
  23. let name_cstr = CStr::from_ptr(name);
  24. match name_cstr.to_bytes() {
  25. b"alnum" => WCTYPE_ALNUM,
  26. b"alpha" => WCTYPE_ALPHA,
  27. b"blank" => WCTYPE_BLANK,
  28. b"cntrl" => WCTYPE_CNTRL,
  29. b"digit" => WCTYPE_DIGIT,
  30. b"graph" => WCTYPE_GRAPH,
  31. b"lower" => WCTYPE_LOWER,
  32. b"print" => WCTYPE_PRINT,
  33. b"punct" => WCTYPE_PUNCT,
  34. b"space" => WCTYPE_SPACE,
  35. b"upper" => WCTYPE_UPPER,
  36. b"xdigit" => WCTYPE_XDIGIT,
  37. _ => 0
  38. }
  39. }
  40. #[no_mangle]
  41. pub extern "C" fn towlower(wc: wint_t) -> wint_t {
  42. casemap(wc, 0)
  43. }
  44. #[no_mangle]
  45. pub extern "C" fn towupper(wc: wint_t) -> wint_t {
  46. casemap(wc, 1)
  47. }