From f65c1c27c7724da7a08048dc7b97b81f84a1beef Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jackpot51@gmail.com> Date: Thu, 10 Nov 2022 10:12:41 -0700 Subject: [PATCH] Implement wcwidth --- Cargo.lock | 1 + Cargo.toml | 1 + src/header/wchar/mod.rs | 10 ++++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ae01cd4f..41a6d11b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,6 +351,7 @@ dependencies = [ "redox_syscall 0.3.2", "sc", "spin 0.9.4", + "unicode-width", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3f163c02a..f4e172353 100644 --- a/Cargo.toml +++ b/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" diff --git a/src/header/wchar/mod.rs b/src/header/wchar/mod.rs index cde6a5e85..93096dad9 100644 --- a/src/header/wchar/mod.rs +++ b/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] -- GitLab