From 1a3c8cbeb4c9ece00e0dd728135cfc5a16e673b7 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Wed, 30 Dec 2020 00:19:24 +0800 Subject: [PATCH] feat: add join_path --- Cargo.toml | 2 +- src/util_file.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8a438e5..d6cf623 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust_util" -version = "0.6.23" +version = "0.6.24" authors = ["Hatter Jiang "] edition = "2018" description = "Hatter's Rust Util" diff --git a/src/util_file.rs b/src/util_file.rs index 5a34fd3..ff48814 100644 --- a/src/util_file.rs +++ b/src/util_file.rs @@ -60,6 +60,15 @@ impl Iterator for JoinFilesReader { } } +pub fn join_path(path1: &str, path2: &str) -> String { + let sp = if util_os::is_macos_or_linux() { "/" } else { "\\" }; + if path1.ends_with(sp) { + path1.to_string() + path2 + } else { + path1.to_string() + sp + path2 + } +} + pub fn find_parents_exists_file(file: &str) -> Option { let mut loop_count = 0_usize; match PathBuf::from(".").canonicalize() {