From 512a6a32010f0184d5ee1fcc0b459b7837346aad Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Wed, 6 Jan 2016 16:34:58 +0100 Subject: [PATCH] expand, unexpand: fix build on stable --- src/uucore/lib.rs | 1 + src/uucore/utf8.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/uucore/utf8.rs diff --git a/src/uucore/lib.rs b/src/uucore/lib.rs index f5788e8d6..53a02aca2 100644 --- a/src/uucore/lib.rs +++ b/src/uucore/lib.rs @@ -7,6 +7,7 @@ mod macros; pub mod fs; pub mod parse_time; +pub mod utf8; #[cfg(unix)] pub mod c_types; #[cfg(unix)] pub mod process; diff --git a/src/uucore/utf8.rs b/src/uucore/utf8.rs new file mode 100644 index 000000000..a6c48b785 --- /dev/null +++ b/src/uucore/utf8.rs @@ -0,0 +1,28 @@ +/* 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; +} +