mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-03 22:47:46 +00:00
initial work
This commit is contained in:
parent
ac7e289d29
commit
0c117eb8a8
5 changed files with 6 additions and 16 deletions
|
@ -1,6 +1,4 @@
|
||||||
#![crate_name = "expand"]
|
#![crate_name = "expand"]
|
||||||
#![feature(unicode)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
*
|
*
|
||||||
|
@ -14,14 +12,12 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate rustc_unicode;
|
|
||||||
extern crate unicode_width;
|
extern crate unicode_width;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
use rustc_unicode::str::utf8_char_width;
|
|
||||||
use unicode_width::UnicodeWidthChar;
|
use unicode_width::UnicodeWidthChar;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
|
@ -177,7 +173,7 @@ fn expand(options: Options) {
|
||||||
|
|
||||||
while byte < buf.len() {
|
while byte < buf.len() {
|
||||||
let (ctype, cwidth, nbytes) = if options.uflag {
|
let (ctype, cwidth, nbytes) = if options.uflag {
|
||||||
let nbytes = utf8_char_width(buf[byte]);
|
let nbytes = UnicodeWidthChar::width(buf[byte] as char).unwrap_or(0);
|
||||||
|
|
||||||
if byte + nbytes > buf.len() {
|
if byte + nbytes > buf.len() {
|
||||||
// don't overrun buffer because of invalid UTF-8
|
// don't overrun buffer because of invalid UTF-8
|
||||||
|
|
|
@ -11,7 +11,6 @@ use std::iter::Peekable;
|
||||||
use std::io::{BufRead, Lines};
|
use std::io::{BufRead, Lines};
|
||||||
use std::slice::Iter;
|
use std::slice::Iter;
|
||||||
use std::str::CharRange;
|
use std::str::CharRange;
|
||||||
use rustc_unicode::str::UnicodeStr;
|
|
||||||
use unicode_width::UnicodeWidthChar;
|
use unicode_width::UnicodeWidthChar;
|
||||||
use FileOrStdReader;
|
use FileOrStdReader;
|
||||||
use FmtOptions;
|
use FmtOptions;
|
||||||
|
@ -157,7 +156,7 @@ impl<'a> Iterator for FileLines<'a> {
|
||||||
// emit a blank line
|
// emit a blank line
|
||||||
// Err(true) indicates that this was a linebreak,
|
// Err(true) indicates that this was a linebreak,
|
||||||
// which is important to know when detecting mail headers
|
// which is important to know when detecting mail headers
|
||||||
if n.is_whitespace() {
|
if n.chars().all(|c| c.is_whitespace()) {
|
||||||
return Some(Line::NoFormatLine("\n".to_string(), true));
|
return Some(Line::NoFormatLine("\n".to_string(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +165,7 @@ impl<'a> Iterator for FileLines<'a> {
|
||||||
let (pmatch, poffset) = self.match_prefix(&n[..]);
|
let (pmatch, poffset) = self.match_prefix(&n[..]);
|
||||||
if !pmatch {
|
if !pmatch {
|
||||||
return Some(Line::NoFormatLine(n, false));
|
return Some(Line::NoFormatLine(n, false));
|
||||||
} else if n[poffset + self.opts.prefix.len()..].is_whitespace() {
|
} else if n[poffset + self.opts.prefix.len()..].chars().all(|c| c.is_whitespace()) {
|
||||||
// if the line matches the prefix, but is blank after,
|
// if the line matches the prefix, but is blank after,
|
||||||
// don't allow lines to be combined through it (that is,
|
// don't allow lines to be combined through it (that is,
|
||||||
// treat it like a blank line, except that since it's
|
// treat it like a blank line, except that since it's
|
||||||
|
|
|
@ -227,7 +227,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
opts.optflag("", "version", "output version information and exit");
|
opts.optflag("", "version", "output version information and exit");
|
||||||
|
|
||||||
let mut options = ProgramOptions {stdin: BufferType::Default, stdout: BufferType::Default, stderr: BufferType::Default};
|
let mut options = ProgramOptions {stdin: BufferType::Default, stdout: BufferType::Default, stderr: BufferType::Default};
|
||||||
let mut command_idx = -1;
|
let mut command_idx: i32 = -1;
|
||||||
for i in 1 .. args.len()+1 {
|
for i in 1 .. args.len()+1 {
|
||||||
match parse_options(&args[1 .. i], &mut options, &opts) {
|
match parse_options(&args[1 .. i], &mut options, &opts) {
|
||||||
Ok(OkMsg::Buffering) => {
|
Ok(OkMsg::Buffering) => {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#![crate_name = "tr"]
|
#![crate_name = "tr"]
|
||||||
#![feature(io)]
|
#![feature(io)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
#![crate_name = "unexpand"]
|
#![crate_name = "unexpand"]
|
||||||
#![feature(unicode)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
*
|
*
|
||||||
|
@ -14,13 +12,11 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate rustc_unicode;
|
|
||||||
extern crate unicode_width;
|
extern crate unicode_width;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Stdout, Write};
|
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Stdout, Write};
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
use rustc_unicode::str::utf8_char_width;
|
|
||||||
use unicode_width::UnicodeWidthChar;
|
use unicode_width::UnicodeWidthChar;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
|
@ -210,7 +206,7 @@ fn unexpand(options: Options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let (ctype, cwidth, nbytes) = if options.uflag {
|
let (ctype, cwidth, nbytes) = if options.uflag {
|
||||||
let nbytes = utf8_char_width(buf[byte]);
|
let nbytes = UnicodeWidthChar::width(buf[byte] as char).unwrap_or(0);
|
||||||
|
|
||||||
// figure out how big the next char is, if it's UTF-8
|
// figure out how big the next char is, if it's UTF-8
|
||||||
if byte + nbytes > buf.len() {
|
if byte + nbytes > buf.len() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue