1 //! Random and miscellaneous utils used in ouch.
3 //! In here we have the logic for custom formatting, some file and directory utils, and user
4 //! stdin interaction helpers.
11 pub use formatting::{concatenate_os_str_list, nice_directory_display, strip_cur_dir, to_utf, Bytes};
12 pub use fs::{cd_into_same_dir_as, clear_path, create_dir_if_non_existent, dir_is_empty, try_infer_extension};
14 create_or_ask_overwrite, user_wants_to_continue_compressing, user_wants_to_continue_decompressing,
15 user_wants_to_overwrite, QuestionPolicy,
17 pub use utf8::{get_invalid_utf8_paths, is_invalid_utf8};
20 use std::{ffi::OsStr, path::PathBuf};
22 /// Check, without allocating, if os_str can be converted into &str
23 pub fn is_invalid_utf8(os_str: impl AsRef<OsStr>) -> bool {
24 os_str.as_ref().to_str().is_none()
27 /// Filter out list of paths that are not utf8 valid
28 pub fn get_invalid_utf8_paths(paths: &[PathBuf]) -> Vec<&PathBuf> {
29 paths.iter().filter_map(|path| is_invalid_utf8(path).then(|| path)).collect()