diff --git a/src/expand/expand.rs b/src/expand/expand.rs index 6b358e90c..7430aa1ea 100644 --- a/src/expand/expand.rs +++ b/src/expand/expand.rs @@ -179,7 +179,7 @@ fn expand(options: Options) { while byte < buf.len() { let (ctype, cwidth, nbytes) = if options.uflag { - let nbytes = uucore::utf8::utf8_char_width(buf[byte]); + let nbytes = char::from(buf[byte]).len_utf8(); if byte + nbytes > buf.len() { // don't overrun buffer because of invalid UTF-8 diff --git a/src/unexpand/Cargo.toml b/src/unexpand/Cargo.toml index b917a95de..cecad138a 100644 --- a/src/unexpand/Cargo.toml +++ b/src/unexpand/Cargo.toml @@ -14,7 +14,6 @@ unicode-width = "0.1.5" [dependencies.uucore] path = "../uucore" -features = ["utf8"] [[bin]] name = "unexpand" diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index 30b7343ec..5df0dfda0 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -239,7 +239,7 @@ fn unexpand(options: Options) { } let (ctype, cwidth, nbytes) = if options.uflag { - let nbytes = uucore::utf8::utf8_char_width(buf[byte]); + let nbytes = char::from(buf[byte]).len_utf8(); // figure out how big the next char is, if it's UTF-8 if byte + nbytes > buf.len() { diff --git a/src/uucore/lib.rs b/src/uucore/lib.rs index bfa111564..e391d6975 100644 --- a/src/uucore/lib.rs +++ b/src/uucore/lib.rs @@ -18,8 +18,6 @@ pub mod panic; #[cfg(feature = "fs")] pub mod fs; -#[cfg(feature = "utf8")] -pub mod utf8; #[cfg(feature = "encoding")] pub mod encoding; #[cfg(feature = "parse_time")] diff --git a/src/uucore/utf8.rs b/src/uucore/utf8.rs deleted file mode 100644 index f2d2137a2..000000000 --- a/src/uucore/utf8.rs +++ /dev/null @@ -1,27 +0,0 @@ -/* This is taken from the rust_unicode crate. Remove once 'unicode' becomes stable */ - -// https://tools.ietf.org/html/rfc3629 -static UTF8_CHAR_WIDTH: [u8; 256] = [ -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1F -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x3F -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x5F -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x7F -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x9F -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xBF -0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2, -2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xDF -3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, // 0xEF -4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0, // 0xFF -]; - -/// Given a first byte, determine how many bytes are in this UTF-8 character -#[inline] -pub fn utf8_char_width(b: u8) -> usize { - return UTF8_CHAR_WIDTH[b as usize] as usize; -}