mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #3832 from tertsdiepraam/simplify-encoding-handling
Simplify invalid encoding handling
This commit is contained in:
commit
87e3899477
48 changed files with 104 additions and 298 deletions
|
@ -12,7 +12,7 @@ use std::io::{stdout, Read, Write};
|
|||
use uucore::display::Quotable;
|
||||
use uucore::encoding::{wrap_print, Data, Format};
|
||||
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Stdin};
|
||||
|
@ -87,9 +87,7 @@ impl Config {
|
|||
|
||||
pub fn parse_base_cmd_args(args: impl uucore::Args, about: &str, usage: &str) -> UResult<Config> {
|
||||
let command = base_app(about, usage);
|
||||
let arg_list = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let arg_list = args.collect_lossy();
|
||||
Config::from(&command.try_get_matches_from(arg_list)?)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use clap::{crate_version, Arg, Command};
|
|||
use std::path::{is_separator, PathBuf};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{UResult, UUsageError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static ABOUT: &str = r#"Print NAME with any leading directory components removed
|
||||
If specified, also remove a trailing SUFFIX"#;
|
||||
|
@ -28,9 +28,7 @@ pub mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
// Since options have to go before names,
|
||||
// if the first argument is not an option, then there is no option,
|
||||
|
|
|
@ -14,7 +14,6 @@ use uu_base32::base_common::{self, Config, BASE_CMD_PARSE_ERROR};
|
|||
use uucore::{
|
||||
encoding::Format,
|
||||
error::{UResult, UUsageError},
|
||||
InvalidEncodingHandling,
|
||||
};
|
||||
|
||||
use std::io::{stdin, Read};
|
||||
|
@ -52,10 +51,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
|
||||
fn parse_cmd_args(args: impl uucore::Args) -> UResult<(Config, Format)> {
|
||||
let matches = uu_app()
|
||||
.try_get_matches_from(
|
||||
args.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any(),
|
||||
)
|
||||
.try_get_matches_from(args.collect_lossy())
|
||||
.with_exit_code(1)?;
|
||||
let format = ENCODINGS
|
||||
.iter()
|
||||
|
|
|
@ -36,7 +36,7 @@ use std::net::Shutdown;
|
|||
use std::os::unix::fs::FileTypeExt;
|
||||
#[cfg(unix)]
|
||||
use unix_socket::UnixStream;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static NAME: &str = "cat";
|
||||
static USAGE: &str = "{} [OPTION]... [FILE]...";
|
||||
|
@ -184,9 +184,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().try_get_matches_from(args)?;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ use uucore::fs::is_symlink;
|
|||
use uucore::libc::mode_t;
|
||||
#[cfg(not(windows))]
|
||||
use uucore::mode;
|
||||
use uucore::{format_usage, show_error, InvalidEncodingHandling};
|
||||
use uucore::{format_usage, show_error};
|
||||
|
||||
static ABOUT: &str = "Change the mode of each FILE to MODE.
|
||||
With --reference, change the mode of each FILE to that of RFILE.";
|
||||
|
@ -46,9 +46,7 @@ fn get_long_usage() -> String {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let mut args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let mut args = args.collect_lossy();
|
||||
|
||||
// Before we can parse 'args' with clap (and previously getopts),
|
||||
// a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE").
|
||||
|
|
|
@ -17,7 +17,7 @@ use std::path::Path;
|
|||
use std::process;
|
||||
use uucore::error::{set_exit_code, UResult};
|
||||
use uucore::libc::{self, chroot, setgid, setgroups, setuid};
|
||||
use uucore::{entries, format_usage, InvalidEncodingHandling};
|
||||
use uucore::{entries, format_usage};
|
||||
|
||||
static ABOUT: &str = "Run COMMAND with root directory set to NEWROOT.";
|
||||
static USAGE: &str = "{} [OPTION]... NEWROOT [COMMAND [ARG]...]";
|
||||
|
@ -33,9 +33,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ use std::io::{self, stdin, BufReader, Read};
|
|||
use std::path::Path;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult};
|
||||
use uucore::InvalidEncodingHandling;
|
||||
use uucore::{format_usage, show};
|
||||
|
||||
// NOTE: CRC_TABLE_LEN *must* be <= 256 as we cast 0..CRC_TABLE_LEN to u8
|
||||
|
@ -114,9 +113,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::io::{self, stdin, BufRead, BufReader, Stdin};
|
|||
use std::path::Path;
|
||||
use uucore::error::FromIo;
|
||||
use uucore::error::UResult;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
use clap::{crate_version, Arg, ArgMatches, Command};
|
||||
|
||||
|
@ -132,9 +132,7 @@ fn open_file(name: &str) -> io::Result<LineReader> {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
let filename1 = matches.value_of(options::FILE_1).unwrap();
|
||||
|
|
|
@ -16,7 +16,7 @@ use clap::{crate_version, Arg, ArgMatches, Command};
|
|||
use regex::Regex;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
mod csplit_error;
|
||||
mod patterns;
|
||||
|
@ -713,9 +713,7 @@ mod tests {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ use uucore::display::Quotable;
|
|||
use uucore::error::{FromIo, UResult, USimpleError};
|
||||
|
||||
use self::searcher::Searcher;
|
||||
use uucore::format_usage;
|
||||
use uucore::ranges::Range;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
|
||||
mod searcher;
|
||||
|
||||
|
@ -398,9 +398,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let delimiter_is_equal = args.contains(&"-d=".to_string()); // special case
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
|
|
@ -37,7 +37,7 @@ use clap::{crate_version, Arg, ArgMatches, Command};
|
|||
use gcd::Gcd;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult};
|
||||
use uucore::{show_error, InvalidEncodingHandling};
|
||||
use uucore::show_error;
|
||||
|
||||
const ABOUT: &str = "copy, and optionally convert, a file system resource";
|
||||
const BUF_INIT_BYTE: u8 = 0xDD;
|
||||
|
@ -706,8 +706,7 @@ fn append_dashes_if_not_present(mut acc: Vec<String>, mut s: String) -> Vec<Stri
|
|||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let dashed_args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any()
|
||||
.collect_ignore()
|
||||
.into_iter()
|
||||
.fold(Vec::new(), append_dashes_if_not_present);
|
||||
|
||||
|
|
|
@ -65,9 +65,7 @@ pub fn guess_syntax() -> OutputFmt {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(&args);
|
||||
|
||||
|
@ -278,7 +276,7 @@ enum ParseState {
|
|||
}
|
||||
|
||||
use std::collections::HashMap;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
fn parse<T>(lines: T, fmt: &OutputFmt, fp: &str) -> Result<String, String>
|
||||
where
|
||||
|
|
|
@ -9,7 +9,7 @@ use clap::{crate_version, Arg, Command};
|
|||
use std::path::Path;
|
||||
use uucore::display::print_verbatim;
|
||||
use uucore::error::{UResult, UUsageError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static ABOUT: &str = "strip last component from file name";
|
||||
const USAGE: &str = "{} [OPTION] NAME...";
|
||||
|
@ -28,9 +28,7 @@ fn get_long_usage() -> String {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let after_help = get_long_usage();
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ use uucore::error::{UError, UResult};
|
|||
use uucore::format_usage;
|
||||
use uucore::parse_glob;
|
||||
use uucore::parse_size::{parse_size, ParseSizeError};
|
||||
use uucore::InvalidEncodingHandling;
|
||||
#[cfg(windows)]
|
||||
use winapi::shared::minwindef::{DWORD, LPVOID};
|
||||
#[cfg(windows)]
|
||||
|
@ -516,9 +515,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult<Vec<Pattern>> {
|
|||
#[uucore::main]
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use std::io::{self, Write};
|
|||
use std::iter::Peekable;
|
||||
use std::str::Chars;
|
||||
use uucore::error::{FromIo, UResult};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
const NAME: &str = "echo";
|
||||
const ABOUT: &str = "display a line of text";
|
||||
|
@ -110,9 +110,7 @@ fn print_escaped(input: &str, mut output: impl Write) -> io::Result<bool> {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
let no_newline = matches.contains_id(options::NO_NEWLINE);
|
||||
|
|
|
@ -22,7 +22,7 @@ use std::str::from_utf8;
|
|||
use unicode_width::UnicodeWidthChar;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UError, UResult};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static ABOUT: &str = "Convert tabs in each FILE to spaces, writing to standard output.
|
||||
With no FILE, or when FILE is -, read standard input.";
|
||||
|
@ -269,9 +269,7 @@ fn expand_shortcuts(args: &[String]) -> Vec<String> {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(expand_shortcuts(&args));
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
use clap::{crate_version, Arg, Command};
|
||||
use uucore::error::{UResult, USimpleError};
|
||||
use uucore::InvalidEncodingHandling;
|
||||
|
||||
mod syntax_tree;
|
||||
mod tokens;
|
||||
|
@ -33,9 +32,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
// For expr utility we do not want getopts.
|
||||
// The following usage should work without escaping hyphens: `expr -15 = 1 + 2 \* \( 3 - -4 \)`
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::io::{stdin, BufRead, BufReader, Read};
|
|||
use std::path::Path;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult, USimpleError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
const TAB_WIDTH: usize = 8;
|
||||
|
||||
|
@ -31,9 +31,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let (args, obs_width) = handle_obsolete(&args[..]);
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
|
|
@ -16,8 +16,8 @@ use nix::unistd::Pid;
|
|||
use std::io::Error;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UError, UResult, USimpleError};
|
||||
use uucore::format_usage;
|
||||
use uucore::signals::{signal_by_name_or_value, ALL_SIGNALS};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
|
||||
static ABOUT: &str = "Send signal to processes or list information about signals.";
|
||||
const USAGE: &str = "{} [OPTIONS]... PID...";
|
||||
|
@ -38,9 +38,7 @@ pub enum Mode {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let mut args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let mut args = args.collect_ignore();
|
||||
let obs_signal = handle_obsolete(&mut args);
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
|
|
@ -15,7 +15,6 @@ extern crate uucore;
|
|||
use clap::{crate_version, Command};
|
||||
use std::ffi::CStr;
|
||||
use uucore::error::UResult;
|
||||
use uucore::InvalidEncodingHandling;
|
||||
|
||||
extern "C" {
|
||||
// POSIX requires using getlogin (or equivalent code)
|
||||
|
@ -37,9 +36,7 @@ static ABOUT: &str = "Print user's login name";
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let _ = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -15,10 +15,10 @@ use std::path::{Path, PathBuf};
|
|||
#[cfg(not(windows))]
|
||||
use uucore::error::FromIo;
|
||||
use uucore::error::{UResult, USimpleError};
|
||||
use uucore::format_usage;
|
||||
#[cfg(not(windows))]
|
||||
use uucore::mode;
|
||||
use uucore::{display::Quotable, fs::dir_strip_dot_for_creation};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
|
||||
static DEFAULT_PERM: u32 = 0o755;
|
||||
|
||||
|
@ -83,9 +83,7 @@ fn strip_minus_from_mode(args: &mut Vec<String>) -> bool {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let mut args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let mut args = args.collect_lossy();
|
||||
|
||||
// Before we can parse 'args' with clap (and previously getopts),
|
||||
// a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE").
|
||||
|
|
|
@ -11,9 +11,9 @@ extern crate uucore;
|
|||
use clap::{crate_version, Arg, Command};
|
||||
use libc::mkfifo;
|
||||
use std::ffi::CString;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{UResult, USimpleError};
|
||||
use uucore::format_usage;
|
||||
use uucore::{display::Quotable, InvalidEncodingHandling};
|
||||
|
||||
static NAME: &str = "mkfifo";
|
||||
static USAGE: &str = "{} [OPTION]... NAME...";
|
||||
|
@ -28,9 +28,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use libc::{S_IFBLK, S_IFCHR, S_IFIFO, S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOT
|
|||
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{set_exit_code, UResult, USimpleError, UUsageError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static ABOUT: &str = "Create the special file NAME of the given TYPE.";
|
||||
static USAGE: &str = "{} [OPTION]... NAME TYPE [MAJOR MINOR]";
|
||||
|
@ -81,9 +81,7 @@ fn _mknod(file_name: &str, mode: mode_t, dev: dev_t) -> i32 {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
// Linux-specific options, not implemented
|
||||
// opts.optflag("Z", "", "set the SELinux security context to default type");
|
||||
// opts.optopt("", "context", "like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX");
|
||||
|
|
|
@ -316,7 +316,7 @@ impl Params {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args.collect_str_lossy().accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().try_get_matches_from(&args)?;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ use std::io::{stdin, BufRead, BufReader, Read};
|
|||
use std::iter::repeat;
|
||||
use std::path::Path;
|
||||
use uucore::error::{FromIo, UResult, USimpleError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
mod helper;
|
||||
|
||||
|
@ -84,9 +84,7 @@ pub mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ use std::os::unix::prelude::*;
|
|||
use std::path::{Path, PathBuf};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{set_exit_code, UError, UResult};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static ABOUT: &str = "Run COMMAND ignoring hangup signals.";
|
||||
static LONG_HELP: &str = "
|
||||
|
@ -86,9 +86,7 @@ impl Display for NohupError {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ use std::io::{BufRead, Write};
|
|||
use units::{IEC_BASES, SI_BASES};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::UResult;
|
||||
use uucore::format_usage;
|
||||
use uucore::ranges::Range;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
|
||||
pub mod errors;
|
||||
pub mod format;
|
||||
|
@ -261,9 +261,7 @@ fn concat_format_arg_and_value(args: &[String]) -> Vec<String> {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(concat_format_arg_and_value(&args));
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ use uucore::display::Quotable;
|
|||
use uucore::error::{UResult, USimpleError};
|
||||
use uucore::format_usage;
|
||||
use uucore::parse_size::ParseSizeError;
|
||||
use uucore::InvalidEncodingHandling;
|
||||
|
||||
const PEEK_BUFFER_SIZE: usize = 4; // utf-8 can be 4 bytes
|
||||
static ABOUT: &str = "dump files in octal and other formats";
|
||||
|
@ -256,9 +255,7 @@ impl OdOptions {
|
|||
/// opens the input and calls `odfunc` to process the input.
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let clap_opts = uu_app();
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::fs;
|
|||
use std::io::{ErrorKind, Write};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{set_exit_code, UResult, UUsageError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
// operating mode
|
||||
enum Mode {
|
||||
|
@ -39,9 +39,7 @@ const POSIX_NAME_MAX: usize = 14;
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::os::unix::fs::MetadataExt;
|
|||
|
||||
use clap::{crate_version, Arg, Command};
|
||||
use std::path::PathBuf;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static ABOUT: &str = "lightweight finger";
|
||||
const USAGE: &str = "{} [OPTION]... [USER]...";
|
||||
|
@ -49,9 +49,7 @@ fn get_long_usage() -> String {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let after_help = get_long_usage();
|
||||
|
||||
|
|
|
@ -378,9 +378,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(uucore::InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let opt_args = recreate_arguments(&args);
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
use clap::{crate_version, Arg, Command};
|
||||
use uucore::error::{UResult, UUsageError};
|
||||
use uucore::InvalidEncodingHandling;
|
||||
use uucore::{format_usage, memo};
|
||||
|
||||
const VERSION: &str = "version";
|
||||
|
@ -271,9 +270,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
let format_string = matches
|
||||
|
|
|
@ -19,7 +19,7 @@ use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
|||
use std::num::ParseIntError;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UError, UResult};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static NAME: &str = "ptx";
|
||||
const USAGE: &str = "\
|
||||
|
@ -722,9 +722,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
// let mut opts = Options::new();
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
|
|
@ -12,8 +12,8 @@ use std::env;
|
|||
use std::path::{Path, PathBuf};
|
||||
use uucore::display::println_verbatim;
|
||||
use uucore::error::{FromIo, UResult};
|
||||
use uucore::format_usage;
|
||||
use uucore::fs::{canonicalize, MissingHandling, ResolveMode};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
|
||||
static ABOUT: &str = "Convert TO destination to the relative path from the FROM dir.
|
||||
If FROM path is omitted, current working dir will be used.";
|
||||
|
@ -27,9 +27,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::io::SeekFrom;
|
|||
use std::path::{Path, PathBuf};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
|
||||
use uucore::{format_usage, util_name, InvalidEncodingHandling};
|
||||
use uucore::{format_usage, util_name};
|
||||
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
@ -266,9 +266,7 @@ pub mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ use std::fs::File;
|
|||
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult, USimpleError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
mod rand_read_adapter;
|
||||
|
||||
|
@ -56,9 +56,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -47,9 +47,9 @@ use std::str::Utf8Error;
|
|||
use unicode_width::UnicodeWidthStr;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{set_exit_code, strip_errno, UError, UResult, USimpleError, UUsageError};
|
||||
use uucore::format_usage;
|
||||
use uucore::parse_size::{parse_size, ParseSizeError};
|
||||
use uucore::version_cmp::version_cmp;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
|
||||
use crate::tmp_dir::TmpDirWrapper;
|
||||
|
||||
|
@ -1055,9 +1055,7 @@ fn make_sort_mode_arg<'a>(mode: &'a str, short: char, help: &'a str) -> Arg<'a>
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
let mut settings: GlobalSettings = Default::default();
|
||||
|
||||
let matches = match uu_app().try_get_matches_from(args) {
|
||||
|
|
|
@ -19,8 +19,8 @@ use std::process;
|
|||
use tempfile::tempdir;
|
||||
use tempfile::TempDir;
|
||||
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
|
||||
use uucore::format_usage;
|
||||
use uucore::parse_size::parse_size;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
|
||||
static ABOUT: &str =
|
||||
"Run COMMAND, with modified buffering operations for its standard streams.\n\n\
|
||||
|
@ -156,9 +156,7 @@ fn get_preload_env(tmp_dir: &mut TempDir) -> io::Result<(String, PathBuf)> {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ use std::io::{stdin, Read};
|
|||
use std::path::Path;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult, USimpleError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static NAME: &str = "sum";
|
||||
static USAGE: &str = "{} [OPTION]... [FILE]...";
|
||||
|
@ -109,9 +109,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ use std::{
|
|||
use uucore::display::Quotable;
|
||||
use uucore::error::UError;
|
||||
use uucore::error::UResult;
|
||||
use uucore::InvalidEncodingHandling;
|
||||
use uucore::{format_usage, show};
|
||||
|
||||
use crate::error::TacError;
|
||||
|
@ -37,9 +36,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ use std::process::{self, Child, Stdio};
|
|||
use std::time::Duration;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{UResult, USimpleError, UUsageError};
|
||||
use uucore::format_usage;
|
||||
use uucore::process::ChildExt;
|
||||
use uucore::signals::{signal_by_name_or_value, signal_name_by_value};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
|
||||
static ABOUT: &str = "Start COMMAND, and kill it if still running after DURATION.";
|
||||
const USAGE: &str = "{} [OPTION] DURATION COMMAND...";
|
||||
|
@ -106,9 +106,7 @@ impl Config {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let command = uu_app();
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ use std::io::{stdin, stdout, BufReader, BufWriter};
|
|||
use uucore::{format_usage, show};
|
||||
|
||||
use crate::operation::DeleteOperation;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{UResult, USimpleError, UUsageError};
|
||||
use uucore::{display::Quotable, InvalidEncodingHandling};
|
||||
|
||||
static ABOUT: &str = "translate or delete characters";
|
||||
const USAGE: &str = "{} [OPTION]... SET1 [SET2]";
|
||||
|
@ -40,9 +40,7 @@ fn get_long_usage() -> String {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let after_help = get_long_usage();
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::io::{stdin, BufRead, BufReader, Read};
|
|||
use std::path::Path;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UResult, USimpleError};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static ABOUT: &str = "Topological sort the strings in FILE.
|
||||
Strings are defined as any sequence of tokens separated by whitespace (tab, space, or newline).
|
||||
|
@ -25,9 +25,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use clap::{crate_version, Arg, Command};
|
|||
use std::ffi::CStr;
|
||||
use std::io::Write;
|
||||
use uucore::error::UResult;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static ABOUT: &str = "Print the file name of the terminal connected to standard input.";
|
||||
const USAGE: &str = "{} [OPTION]...";
|
||||
|
@ -24,9 +24,7 @@ mod options {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
.accept_any();
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ use std::str::from_utf8;
|
|||
use unicode_width::UnicodeWidthChar;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UError, UResult};
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
static NAME: &str = "unexpand";
|
||||
static USAGE: &str = "{} [OPTION]... [FILE]...";
|
||||
|
@ -165,9 +165,7 @@ fn expand_shortcuts(args: &[String]) -> Vec<String> {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let matches = uu_app().get_matches_from(expand_shortcuts(&args));
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ use std::ffi::CStr;
|
|||
use std::fmt::Write;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::path::PathBuf;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
use uucore::format_usage;
|
||||
|
||||
mod options {
|
||||
pub const ALL: &str = "all";
|
||||
|
@ -56,9 +56,7 @@ fn get_long_usage() -> String {
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
let args = args.collect_ignore();
|
||||
|
||||
let after_help = get_long_usage();
|
||||
|
||||
|
|
|
@ -82,8 +82,6 @@ use std::sync::atomic::Ordering;
|
|||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::display::Quotable;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! bin {
|
||||
($util:ident) => {
|
||||
|
@ -150,95 +148,15 @@ pub fn execution_phrase() -> &'static str {
|
|||
&EXECUTION_PHRASE
|
||||
}
|
||||
|
||||
pub enum InvalidEncodingHandling {
|
||||
Ignore,
|
||||
ConvertLossy,
|
||||
Panic,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub enum ConversionResult {
|
||||
Complete(Vec<String>),
|
||||
Lossy(Vec<String>),
|
||||
}
|
||||
|
||||
impl ConversionResult {
|
||||
pub fn accept_any(self) -> Vec<String> {
|
||||
match self {
|
||||
Self::Complete(result) | Self::Lossy(result) => result,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_lossy(self, msg: &str) -> Vec<String> {
|
||||
match self {
|
||||
Self::Lossy(result) => result,
|
||||
Self::Complete(_) => {
|
||||
panic!("{}", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_complete(self, msg: &str) -> Vec<String> {
|
||||
match self {
|
||||
Self::Complete(result) => result,
|
||||
Self::Lossy(_) => {
|
||||
panic!("{}", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Args: Iterator<Item = OsString> + Sized {
|
||||
/// Converts each iterator item to a String and collects these into a vector
|
||||
/// On invalid encoding, the result will depend on the argument. This method allows to either drop entries with illegal encoding
|
||||
/// completely (```InvalidEncodingHandling::Ignore```), convert them using lossy-conversion (```InvalidEncodingHandling::ConvertLossy```)
|
||||
/// which will result in strange strings or can chosen to panic (```InvalidEncodingHandling::Panic```).
|
||||
/// # Arguments
|
||||
/// * `handling` - This switch allows to switch the behavior, when invalid encoding is encountered
|
||||
/// # Panics
|
||||
/// * Occurs, when invalid encoding is encountered and handling is set to ```InvalidEncodingHandling::Panic```
|
||||
fn collect_str(self, handling: InvalidEncodingHandling) -> ConversionResult {
|
||||
let mut full_conversion = true;
|
||||
let result_vector: Vec<String> = self
|
||||
.map(|s| match s.into_string() {
|
||||
Ok(string) => Ok(string),
|
||||
Err(s_ret) => {
|
||||
full_conversion = false;
|
||||
eprintln!(
|
||||
"Input with broken encoding occurred! (s = {}) ",
|
||||
s_ret.quote()
|
||||
);
|
||||
match handling {
|
||||
InvalidEncodingHandling::Ignore => Err(String::new()),
|
||||
InvalidEncodingHandling::ConvertLossy => {
|
||||
Err(s_ret.to_string_lossy().into_owned())
|
||||
}
|
||||
InvalidEncodingHandling::Panic => {
|
||||
panic!("Broken encoding found but caller cannot handle it")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.filter(|s| match handling {
|
||||
InvalidEncodingHandling::Ignore => s.is_ok(),
|
||||
_ => true,
|
||||
})
|
||||
.map(|s| match s {
|
||||
Ok(v) => v,
|
||||
Err(e) => e,
|
||||
})
|
||||
.collect();
|
||||
|
||||
if full_conversion {
|
||||
ConversionResult::Complete(result_vector)
|
||||
} else {
|
||||
ConversionResult::Lossy(result_vector)
|
||||
}
|
||||
/// Collects the iterator into a `Vec<String>`, lossily converting the `OsString`s to `Strings`.
|
||||
fn collect_lossy(self) -> Vec<String> {
|
||||
self.map(|s| s.to_string_lossy().into_owned()).collect()
|
||||
}
|
||||
|
||||
/// convenience function for a more slim interface
|
||||
fn collect_str_lossy(self) -> ConversionResult {
|
||||
self.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||
/// Collects the iterator into a `Vec<String>`, removing any elements that contain invalid encoding.
|
||||
fn collect_ignore(self) -> Vec<String> {
|
||||
self.filter_map(|s| s.into_string().ok()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,46 +179,34 @@ mod tests {
|
|||
]
|
||||
}
|
||||
|
||||
fn collect_os_str(vec: Vec<OsString>, handling: InvalidEncodingHandling) -> ConversionResult {
|
||||
vec.into_iter().collect_str(handling)
|
||||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "redox"))]
|
||||
fn test_invalid_utf8_args_lossy(os_str: &OsStr) {
|
||||
//assert our string is invalid utf8
|
||||
// assert our string is invalid utf8
|
||||
assert!(os_str.to_os_string().into_string().is_err());
|
||||
let test_vec = make_os_vec(os_str);
|
||||
let collected_to_str =
|
||||
collect_os_str(test_vec.clone(), InvalidEncodingHandling::ConvertLossy)
|
||||
.expect_lossy("Lossy conversion expected in this test: bad encoding entries should be converted as good as possible");
|
||||
//conservation of length - when accepting lossy conversion no arguments may be dropped
|
||||
let collected_to_str = test_vec.clone().into_iter().collect_lossy();
|
||||
// conservation of length - when accepting lossy conversion no arguments may be dropped
|
||||
assert_eq!(collected_to_str.len(), test_vec.len());
|
||||
//first indices identical
|
||||
// first indices identical
|
||||
for index in 0..2 {
|
||||
assert_eq!(
|
||||
collected_to_str.get(index).unwrap(),
|
||||
test_vec.get(index).unwrap().to_str().unwrap()
|
||||
);
|
||||
assert_eq!(collected_to_str[index], test_vec[index].to_str().unwrap());
|
||||
}
|
||||
//lossy conversion for string with illegal encoding is done
|
||||
// lossy conversion for string with illegal encoding is done
|
||||
assert_eq!(
|
||||
*collected_to_str.get(2).unwrap(),
|
||||
*collected_to_str[2],
|
||||
os_str.to_os_string().to_string_lossy()
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "redox"))]
|
||||
fn test_invalid_utf8_args_ignore(os_str: &OsStr) {
|
||||
//assert our string is invalid utf8
|
||||
// assert our string is invalid utf8
|
||||
assert!(os_str.to_os_string().into_string().is_err());
|
||||
let test_vec = make_os_vec(os_str);
|
||||
let collected_to_str = collect_os_str(test_vec.clone(), InvalidEncodingHandling::Ignore)
|
||||
.expect_lossy(
|
||||
"Lossy conversion expected in this test: bad encoding entries should be filtered",
|
||||
);
|
||||
//assert that the broken entry is filtered out
|
||||
let collected_to_str = test_vec.clone().into_iter().collect_ignore();
|
||||
// assert that the broken entry is filtered out
|
||||
assert_eq!(collected_to_str.len(), test_vec.len() - 1);
|
||||
//assert that the unbroken indices are converted as expected
|
||||
// assert that the unbroken indices are converted as expected
|
||||
for index in 0..2 {
|
||||
assert_eq!(
|
||||
collected_to_str.get(index).unwrap(),
|
||||
|
@ -311,11 +217,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn valid_utf8_encoding_args() {
|
||||
//create a vector containing only correct encoding
|
||||
// create a vector containing only correct encoding
|
||||
let test_vec = make_os_vec(&OsString::from("test2"));
|
||||
//expect complete conversion without losses, even when lossy conversion is accepted
|
||||
let _ = collect_os_str(test_vec, InvalidEncodingHandling::ConvertLossy)
|
||||
.expect_complete("Lossy conversion not expected in this test");
|
||||
// expect complete conversion without losses, even when lossy conversion is accepted
|
||||
let _ = test_vec.into_iter().collect_lossy();
|
||||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "redox"))]
|
||||
|
|
|
@ -30,7 +30,7 @@ use std::rc::Rc;
|
|||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use tempfile::TempDir;
|
||||
use uucore::{Args, InvalidEncodingHandling};
|
||||
use uucore::Args;
|
||||
|
||||
#[cfg(windows)]
|
||||
static PROGNAME: &str = concat!(env!("CARGO_PKG_NAME"), ".exe");
|
||||
|
@ -1021,8 +1021,7 @@ impl UCommand {
|
|||
let strings = args
|
||||
.iter()
|
||||
.map(|s| s.as_ref().to_os_string())
|
||||
.collect_str(InvalidEncodingHandling::Ignore)
|
||||
.accept_any();
|
||||
.collect_ignore();
|
||||
|
||||
for s in strings {
|
||||
self.comm_string.push(' ');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue