Index: .efiles ================================================================== --- .efiles +++ .efiles @@ -14,5 +14,6 @@ src/tokiox.rs src/tokiox/tcpconn.rs src/serde_parsers.rs examples/fut_if_some.rs examples/deser.rs +examples/slasher.rs Index: Cargo.toml ================================================================== --- Cargo.toml +++ Cargo.toml @@ -1,8 +1,8 @@ [package] name = "orphanage" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "0BSD" # https://crates.io/category_slugs categories = [ "network-programming" ] keywords = [ "sqlite", "fs", "path" ] @@ -32,14 +32,14 @@ async-trait = { version = "0.1.82", optional = true } killswitch = { version = "0.4.2", optional = true } parse-size = { version = "1.1.0", optional = true } rand = { version = "0.8.5" } rusqlite = { version = "0.32.1", optional = true, features = ["functions"] } -serde = { version = "1.0.210", optional = true, features = ["derive"] } +serde = { version = "1.0.214", optional = true, features = ["derive"] } sha2 = { version = "0.10.7", optional = true } shellexpand = { version = "3.1.0" } -tokio = { version = "1.40.0", optional = true, features = [ +tokio = { version = "1.41.0", optional = true, features = [ "macros", "net", "time" ] } [dev-dependencies] killswitch = { version = "0.4.2" } ADDED examples/slasher.rs Index: examples/slasher.rs ================================================================== --- /dev/null +++ examples/slasher.rs @@ -0,0 +1,9 @@ +use orphanage::path::win2unix_sep; + +fn main() { + let winpath = r"c:\foo\bar\baz.txt"; + let pth = win2unix_sep(winpath); + println!("{pth:?}"); +} + +// vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 : Index: src/path.rs ================================================================== --- src/path.rs +++ src/path.rs @@ -131,10 +131,33 @@ } inner(basedir, pth.as_ref()) } + +/// Replace '\` with `/` in a `PathBuf`. +/// +/// On unixy platforms, `\` isn't treated a a path separator, while on Windows +/// both `\` and `/` are treated as path separators, which means that using `/` +/// on Windows is the most portable option. +/// +/// The current implementation converts the path to a string, using +/// `Path::to_str()`, replaces the backslashes with slashes and then converts +/// the string back to a `PathBuf`. An implication of this is that only paths +/// that are utf-8 compliant can be processed. +#[must_use] +#[allow(clippy::option_if_let_else)] +pub fn win2unix_sep(pth: impl AsRef) -> PathBuf { + let pth = pth.as_ref(); + if let Some(s) = pth.to_str() { + let converted = s.replace('\\', "/"); + PathBuf::from(converted) + } else { + pth.to_path_buf() + } +} + /* /// Expand, perform action on expanded path. pub fn expand_and(input: impl AsRef, f: F) -> Result where Index: src/strx.rs ================================================================== --- src/strx.rs +++ src/strx.rs @@ -53,10 +53,16 @@ #[inline] #[must_use] pub fn is_name_char(c: char) -> bool { c.is_alphanumeric() || c == '_' || c == '-' || c == '.' } + + +pub const OBJNAME_SPEC: &str = "must be non-empty, lead with an alphabetic \ + character, with each following character \ + being alphanumeric, '_', '-' or '.'"; + #[allow(clippy::missing_errors_doc)] pub fn validate_name(s: &str, lead: L, rest: R) -> Result<(), Error> where L: Fn(char) -> bool, Index: www/changelog.md ================================================================== --- www/changelog.md +++ www/changelog.md @@ -1,10 +1,33 @@ # Change Log ## [Unreleased] -[Details](/vdiff?from=orphanage-0.1.0&to=trunk) +[Details](/vdiff?from=orphanage-0.1.2&to=trunk) + +### Added + +### Changed + +### Removed + +--- + +## [0.1.2] - 2024-11-01 + +[Details](/vdiff?from=orphanage-0.1.1&to=orphanage-0.1.2) + +### Added + +- `path::win2unix_sep()` can be used to convert paths with backslashes to + paths with slashes. + +--- + +## [0.1.1] - 2024-10-19 + +[Details](/vdiff?from=orphanage-0.1.0&to=orphanage-0.1.1) ### Added - Add `path::PathExt`, and implement it for `PathBuf`. - `PathBuf::expand()` expands a string to a `PathBuf` and returns it. @@ -11,14 +34,10 @@ - `PathBuf::expand_and()` works like `PathBuf::expand()` but it runs a closure on the expanded pwth before returning it. - `PathBuf::expand_and_canon()` works like `PathBuf::expand_and()` but it canonicalizes the path just before returning it. -### Changed - -### Removed - --- ## [0.1.0] [Details](/vdiff?from=orphanage-0.0.4&to=orphanage-0.1.0)