mirror of
https://github.com/uutils/coreutils
synced 2024-12-19 17:43:52 +00:00
Merge pull request #970 from knight42/remove-vec-map
tr: use HashMap in stdlib instead of vec_map
This commit is contained in:
commit
2dd816739f
2 changed files with 10 additions and 9 deletions
|
@ -9,10 +9,11 @@ path = "tr.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "*"
|
||||
libc = "*"
|
||||
bit-set = "*"
|
||||
vec_map = "0.6.0"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
|
||||
[[bin]]
|
||||
name = "tr"
|
||||
|
|
12
src/tr/tr.rs
12
src/tr/tr.rs
|
@ -13,7 +13,6 @@
|
|||
|
||||
extern crate bit_set;
|
||||
extern crate getopts;
|
||||
extern crate vec_map;
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
@ -21,7 +20,7 @@ extern crate uucore;
|
|||
use bit_set::BitSet;
|
||||
use getopts::Options;
|
||||
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
|
||||
use vec_map::VecMap;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use expand::ExpandSet;
|
||||
|
||||
|
@ -62,7 +61,8 @@ fn delete(set: ExpandSet, complement: bool) {
|
|||
}
|
||||
|
||||
fn tr<'a>(set1: ExpandSet<'a>, mut set2: ExpandSet<'a>) {
|
||||
let mut map = VecMap::new();
|
||||
//let mut map = VecMap::new();
|
||||
let mut map = HashMap::new();
|
||||
let stdout = stdout();
|
||||
let mut buf = String::with_capacity(BUFFER_LEN + 4);
|
||||
|
||||
|
@ -82,10 +82,10 @@ fn tr<'a>(set1: ExpandSet<'a>, mut set2: ExpandSet<'a>) {
|
|||
{
|
||||
let mut chars = buf.chars();
|
||||
|
||||
while let Some(char) = chars.next() {
|
||||
let trc = match map.get(char as usize) {
|
||||
while let Some(ch) = chars.next() {
|
||||
let trc = match map.get(&(ch as usize)) {
|
||||
Some(t) => *t,
|
||||
None => char,
|
||||
None => ch,
|
||||
};
|
||||
safe_unwrap!(writer.write_all(format!("{}", trc).as_ref()));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue