Remove widestring-suffix uses

This removes both the `#[widestrs]` annotation as well as all `"foo"L`
suffixes, and does a `cargo fmt` run on the result
This commit is contained in:
Fabian Boehm
2024-01-12 19:10:56 +01:00
parent ca972f6e0f
commit 09cd7c7ad9
31 changed files with 567 additions and 614 deletions

View File

@@ -27,7 +27,6 @@
use std::os::unix::prelude::*;
pub use wcstoi::*;
use widestring_suffix::widestrs;
/// Wide character version of opendir(). Note that opendir() is guaranteed to set close-on-exec by
/// POSIX (hooray).
@@ -274,7 +273,6 @@ fn norm_path(path: &wstr) -> WString {
/// appropriate for cd. That is, return effectively wd + path while resolving leading ../s from
/// path. The intent here is to allow 'cd' out of a directory which may no longer exist, without
/// allowing 'cd' into a directory that may not exist; see #5341.
#[widestrs]
pub fn path_normalize_for_cd(wd: &wstr, path: &wstr) -> WString {
// Fast paths.
const sep: char = '/';
@@ -302,9 +300,9 @@ pub fn path_normalize_for_cd(wd: &wstr, path: &wstr) -> WString {
let mut erase_count = 0;
for comp in &path_comps {
let mut erase_it = false;
if comp.is_empty() || comp == "."L {
if comp.is_empty() || comp == L!(".") {
erase_it = true;
} else if comp == ".."L && !wd_comps.is_empty() {
} else if comp == L!("..") && !wd_comps.is_empty() {
erase_it = true;
wd_comps.pop();
}

View File

@@ -8,23 +8,22 @@
use super::*;
#[test]
#[widestrs]
fn test_wdirname_wbasename() {
// path, dir, base
struct Test(&'static wstr, &'static wstr, &'static wstr);
const testcases: &[Test] = &[
Test(""L, "."L, "."L),
Test("foo//"L, "."L, "foo"L),
Test("foo//////"L, "."L, "foo"L),
Test("/////foo"L, "/"L, "foo"L),
Test("//foo/////bar"L, "//foo"L, "bar"L),
Test("foo/////bar"L, "foo"L, "bar"L),
Test(L!(""), L!("."), L!(".")),
Test(L!("foo//"), L!("."), L!("foo")),
Test(L!("foo//////"), L!("."), L!("foo")),
Test(L!("/////foo"), L!("/"), L!("foo")),
Test(L!("//foo/////bar"), L!("//foo"), L!("bar")),
Test(L!("foo/////bar"), L!("foo"), L!("bar")),
// Examples given in XPG4.2.
Test("/usr/lib"L, "/usr"L, "lib"L),
Test("usr"L, "."L, "usr"L),
Test("/"L, "/"L, "/"L),
Test("."L, "."L, "."L),
Test(".."L, "."L, ".."L),
Test(L!("/usr/lib"), L!("/usr"), L!("lib")),
Test(L!("usr"), L!("."), L!("usr")),
Test(L!("/"), L!("/"), L!("/")),
Test(L!("."), L!("."), L!(".")),
Test(L!(".."), L!("."), L!("..")),
];
for tc in testcases {
@@ -54,7 +53,7 @@ fn test_wdirname_wbasename() {
let last_slash = longpath.chars().rposition(|c| c == '/').unwrap();
let longpath_dir = &longpath[..last_slash];
assert_eq!(wdirname(&longpath), longpath_dir);
assert_eq!(wbasename(&longpath), "overlong"L);
assert_eq!(wbasename(&longpath), L!("overlong"));
}
#[test]