Browse Source

Implement wcwidth

Jeremy Soller 2 years ago
parent
commit
f65c1c27c7
3 changed files with 10 additions and 2 deletions
  1. 1 0
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 8 2
      src/header/wchar/mod.rs

+ 1 - 0
Cargo.lock

@@ -351,6 +351,7 @@ dependencies = [
  "redox_syscall 0.3.2",
  "sc",
  "spin 0.9.4",
+ "unicode-width",
 ]
 
 [[package]]

+ 1 - 0
Cargo.toml

@@ -25,6 +25,7 @@ posix-regex = { path = "posix-regex", features = ["no_std"] }
 rand = { version = "0.5.5", default-features = false }
 memchr = { version = "2.2.0", default-features = false }
 plain = "0.2"
+unicode-width = "0.1"
 
 [dependencies.goblin]
 version = "0.0.21"

+ 8 - 2
src/header/wchar/mod.rs

@@ -656,9 +656,15 @@ pub extern "C" fn wctob(c: wint_t) -> c_int {
     }
 }
 
-// #[no_mangle]
+#[no_mangle]
 pub extern "C" fn wcwidth(wc: wchar_t) -> c_int {
-    unimplemented!();
+    match char::from_u32(wc as u32) {
+        Some(c) => match unicode_width::UnicodeWidthChar::width(c) {
+            Some(width) => width as c_int,
+            None => -1,
+        },
+        None => -1,
+    }
 }
 
 #[no_mangle]