diff --git a/src/expand/expand.rs b/src/expand/expand.rs index 3098b87e1..09bf427b1 100644 --- a/src/expand/expand.rs +++ b/src/expand/expand.rs @@ -1,4 +1,6 @@ #![crate_name = "expand"] +#![feature(unicode)] + /* * This file is part of the uutils coreutils package. * @@ -12,12 +14,14 @@ extern crate getopts; extern crate libc; +extern crate rustc_unicode; extern crate unicode_width; use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; use std::iter::repeat; use std::str::from_utf8; +use rustc_unicode::str::utf8_char_width; use unicode_width::UnicodeWidthChar; #[path = "../common/util.rs"] @@ -173,7 +177,7 @@ fn expand(options: Options) { while byte < buf.len() { let (ctype, cwidth, nbytes) = if options.uflag { - let nbytes = UnicodeWidthChar::width(buf[byte] as char).unwrap_or(0); + let nbytes = utf8_char_width(buf[byte]); if byte + nbytes > buf.len() { // don't overrun buffer because of invalid UTF-8 diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index 83bae7fc7..af138dcef 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -1,4 +1,6 @@ #![crate_name = "unexpand"] +#![feature(unicode)] + /* * This file is part of the uutils coreutils package. * @@ -12,11 +14,13 @@ extern crate getopts; extern crate libc; +extern crate rustc_unicode; extern crate unicode_width; use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Stdout, Write}; use std::str::from_utf8; +use rustc_unicode::str::utf8_char_width; use unicode_width::UnicodeWidthChar; #[path = "../common/util.rs"] @@ -206,7 +210,7 @@ fn unexpand(options: Options) { } let (ctype, cwidth, nbytes) = if options.uflag { - let nbytes = UnicodeWidthChar::width(buf[byte] as char).unwrap_or(0); + let nbytes = utf8_char_width(buf[byte]); // figure out how big the next char is, if it's UTF-8 if byte + nbytes > buf.len() {