mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
commit
9e500532d0
4 changed files with 37 additions and 45 deletions
|
@ -23,8 +23,6 @@ to compile anywhere, and this is as good a way as any to try and learn it.
|
||||||
Build Instructions
|
Build Instructions
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
NOTE: This currently requires the most current nightly build.
|
|
||||||
|
|
||||||
To simply build all available utilities:
|
To simply build all available utilities:
|
||||||
```
|
```
|
||||||
make
|
make
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "uu_fmt"]
|
#![crate_name = "uu_fmt"]
|
||||||
#![feature(str_char, unicode)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of `fmt` from the uutils coreutils package.
|
* This file is part of `fmt` from the uutils coreutils package.
|
||||||
|
@ -11,7 +10,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate rustc_unicode;
|
|
||||||
extern crate unicode_width;
|
extern crate unicode_width;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
use std::iter::Peekable;
|
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 unicode_width::UnicodeWidthChar;
|
use unicode_width::UnicodeWidthChar;
|
||||||
use FileOrStdReader;
|
use FileOrStdReader;
|
||||||
use FmtOptions;
|
use FmtOptions;
|
||||||
|
@ -100,11 +99,13 @@ impl<'a> FileLines<'a> {
|
||||||
|
|
||||||
if !exact {
|
if !exact {
|
||||||
// we do it this way rather than byte indexing to support unicode whitespace chars
|
// we do it this way rather than byte indexing to support unicode whitespace chars
|
||||||
let mut i = 0;
|
for (i, char) in line.char_indices() {
|
||||||
while (i < line.len()) && line.char_at(i).is_whitespace() {
|
if char.is_whitespace() {
|
||||||
i = match line.char_range_at(i) { CharRange { next: nxi, .. } => nxi };
|
if line[i..].starts_with(pfx) {
|
||||||
if line[i..].starts_with(pfx) {
|
return (true, i);
|
||||||
return (true, i);
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -544,8 +545,9 @@ impl<'a> Iterator for WordSplit<'a> {
|
||||||
let is_start_of_sentence = self.prev_punct && (before_tab.is_some() || word_start_relative > 1);
|
let is_start_of_sentence = self.prev_punct && (before_tab.is_some() || word_start_relative > 1);
|
||||||
|
|
||||||
// now record whether this word ends in punctuation
|
// now record whether this word ends in punctuation
|
||||||
self.prev_punct = match self.string.char_range_at_reverse(self.position) {
|
self.prev_punct = match self.string[..self.position].chars().rev().next() {
|
||||||
CharRange { ch, .. } => WordSplit::is_punctuation(ch)
|
Some(ch) => WordSplit::is_punctuation(ch),
|
||||||
|
_ => panic!("fatal: expected word not to be empty")
|
||||||
};
|
};
|
||||||
|
|
||||||
let (word, word_start_relative, before_tab, after_tab) =
|
let (word, word_start_relative, before_tab, after_tab) =
|
||||||
|
|
60
src/tr/tr.rs
60
src/tr/tr.rs
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "uu_tr"]
|
#![crate_name = "uu_tr"]
|
||||||
#![feature(io)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -21,7 +20,7 @@ extern crate uucore;
|
||||||
|
|
||||||
use bit_set::BitSet;
|
use bit_set::BitSet;
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
use std::io::{stdin, stdout, BufReader, Read, Write};
|
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
|
||||||
use vec_map::VecMap;
|
use vec_map::VecMap;
|
||||||
|
|
||||||
use expand::ExpandSet;
|
use expand::ExpandSet;
|
||||||
|
@ -49,25 +48,22 @@ fn delete(set: ExpandSet, complement: bool) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for c in BufReader::new(stdin()).chars() {
|
let mut reader = BufReader::new(stdin());
|
||||||
match c {
|
|
||||||
Ok(c) if is_allowed(c) => buf.push(c),
|
while let Ok(length) = reader.read_to_string(&mut buf) {
|
||||||
Ok(_) => (),
|
if length == 0 { break }
|
||||||
Err(err) => panic!("{}", err),
|
|
||||||
};
|
let filtered = buf.chars()
|
||||||
if buf.len() >= BUFFER_LEN {
|
.filter(|c| { is_allowed(*c) })
|
||||||
safe_unwrap!(stdout.write_all(&buf[..].as_bytes()));
|
.collect::<String>();
|
||||||
}
|
safe_unwrap!(stdout.write_all(filtered.as_bytes()));
|
||||||
}
|
buf.clear();
|
||||||
if !buf.is_empty() {
|
|
||||||
safe_unwrap!(stdout.write_all(&buf[..].as_bytes()));
|
|
||||||
pipe_flush!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tr<'a>(set1: ExpandSet<'a>, mut set2: ExpandSet<'a>) {
|
fn tr<'a>(set1: ExpandSet<'a>, mut set2: ExpandSet<'a>) {
|
||||||
let mut map = VecMap::new();
|
let mut map = VecMap::new();
|
||||||
let mut stdout = stdout();
|
let stdout = stdout();
|
||||||
let mut buf = String::with_capacity(BUFFER_LEN + 4);
|
let mut buf = String::with_capacity(BUFFER_LEN + 4);
|
||||||
|
|
||||||
let mut s2_prev = '_';
|
let mut s2_prev = '_';
|
||||||
|
@ -77,27 +73,25 @@ fn tr<'a>(set1: ExpandSet<'a>, mut set2: ExpandSet<'a>) {
|
||||||
map.insert(i as usize, s2_prev);
|
map.insert(i as usize, s2_prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
for c in BufReader::new(stdin()).chars() {
|
let mut reader = BufReader::new(stdin());
|
||||||
match c {
|
let mut writer = BufWriter::new(stdout);
|
||||||
Ok(inc) => {
|
|
||||||
let trc = match map.get(&(inc as usize)) {
|
while let Ok(length) = reader.read_to_string(&mut buf) {
|
||||||
|
if length == 0 { break }
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut chars = buf.chars();
|
||||||
|
|
||||||
|
while let Some(char) = chars.next() {
|
||||||
|
let trc = match map.get(&(char as usize)) {
|
||||||
Some(t) => *t,
|
Some(t) => *t,
|
||||||
None => inc,
|
None => char,
|
||||||
};
|
};
|
||||||
buf.push(trc);
|
safe_unwrap!(writer.write_all(format!("{}", trc).as_ref()));
|
||||||
if buf.len() >= BUFFER_LEN {
|
|
||||||
safe_unwrap!(stdout.write_all(&buf[..].as_bytes()));
|
|
||||||
buf.truncate(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
panic!("{}", err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if !buf.is_empty() {
|
buf.clear();
|
||||||
safe_unwrap!(stdout.write_all(&buf[..].as_bytes()));
|
|
||||||
pipe_flush!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue