Logo

Programming-Idioms

History of Idiom 151 > diff from v12 to v13

Edit summary for version 13 by GobbleCock:
New Rust implementation by user [GobbleCock]

Version 12

2017-11-29, 09:34:53

Version 13

2018-06-12, 20:55:54

Idiom #151 Remove string trailing path separator

Remove last character from string p, if this character is the file path separator of current platform.

Note that this also transforms unix root path "/" into empty string!

Idiom #151 Remove string trailing path separator

Remove last character from string p, if this character is the file path separator of current platform.

Note that this also transforms unix root path "/" into empty string!

Extra Keywords
trim
Extra Keywords
trim
Code
let p = if ::std::path::is_separator(p.chars().last().unwrap()) {
    &p[0..p.len()-1]
} else {
    p
};
Doc URL
https://doc.rust-lang.org/stable/std/path/fn.is_separator.html