mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
sort: allow some functions to be called with OsStr
This commit is contained in:
parent
c0c240f194
commit
64c1f16421
1 changed files with 10 additions and 8 deletions
|
@ -20,8 +20,8 @@ mod external_sort;
|
||||||
mod numeric_str_cmp;
|
mod numeric_str_cmp;
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use external_sort::ext_sort;
|
|
||||||
use custom_str_cmp::custom_str_cmp;
|
use custom_str_cmp::custom_str_cmp;
|
||||||
|
use external_sort::ext_sort;
|
||||||
use fnv::FnvHasher;
|
use fnv::FnvHasher;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use numeric_str_cmp::{numeric_str_cmp, NumInfo, NumInfoParseSettings};
|
use numeric_str_cmp::{numeric_str_cmp, NumInfo, NumInfoParseSettings};
|
||||||
|
@ -33,6 +33,7 @@ use smallvec::SmallVec;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::BinaryHeap;
|
use std::collections::BinaryHeap;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::ffi::OsStr;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
||||||
|
@ -1109,10 +1110,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
exec(files, settings)
|
exec(files, settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_to_lines_iter<'a>(
|
fn file_to_lines_iter(
|
||||||
file: &str,
|
file: impl AsRef<OsStr>,
|
||||||
settings: &'a GlobalSettings,
|
settings: &'_ GlobalSettings,
|
||||||
) -> Option<impl Iterator<Item = Line> + 'a> {
|
) -> Option<impl Iterator<Item = Line> + '_> {
|
||||||
let (reader, _) = match open(file) {
|
let (reader, _) = match open(file) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => return None,
|
None => return None,
|
||||||
|
@ -1177,7 +1178,7 @@ fn exec(files: Vec<String>, settings: GlobalSettings) -> i32 {
|
||||||
let mut lines = vec![];
|
let mut lines = vec![];
|
||||||
|
|
||||||
// This is duplicated from fn file_to_lines_iter, but using that function directly results in a performance regression.
|
// This is duplicated from fn file_to_lines_iter, but using that function directly results in a performance regression.
|
||||||
for (file, _) in files.iter().map(|file| open(file)).flatten() {
|
for (file, _) in files.iter().map(open).flatten() {
|
||||||
let buf_reader = BufReader::new(file);
|
let buf_reader = BufReader::new(file);
|
||||||
for line in buf_reader.split(if settings.zero_terminated {
|
for line in buf_reader.split(if settings.zero_terminated {
|
||||||
b'\0'
|
b'\0'
|
||||||
|
@ -1501,7 +1502,8 @@ fn print_sorted<T: Iterator<Item = Line>>(iter: T, settings: &GlobalSettings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// from cat.rs
|
// from cat.rs
|
||||||
fn open(path: &str) -> Option<(Box<dyn Read>, bool)> {
|
fn open(path: impl AsRef<OsStr>) -> Option<(Box<dyn Read>, bool)> {
|
||||||
|
let path = path.as_ref();
|
||||||
if path == "-" {
|
if path == "-" {
|
||||||
let stdin = stdin();
|
let stdin = stdin();
|
||||||
return Some((Box::new(stdin) as Box<dyn Read>, is_stdin_interactive()));
|
return Some((Box::new(stdin) as Box<dyn Read>, is_stdin_interactive()));
|
||||||
|
@ -1510,7 +1512,7 @@ fn open(path: &str) -> Option<(Box<dyn Read>, bool)> {
|
||||||
match File::open(Path::new(path)) {
|
match File::open(Path::new(path)) {
|
||||||
Ok(f) => Some((Box::new(f) as Box<dyn Read>, false)),
|
Ok(f) => Some((Box::new(f) as Box<dyn Read>, false)),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
show_error!("{0}: {1}", path, e.to_string());
|
show_error!("{0:?}: {1}", path, e.to_string());
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue