mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
Prefer taking native Rust strings instead of wcharz_t
We should only be dealing with wcharz_t at the language boundary. Rust callers should prefer the equivalent &wstr. Since wcsfilecmp() is no longer exposed directly it can take &wstr only.
This commit is contained in:
parent
a446a16471
commit
dcca3cfe3c
2 changed files with 8 additions and 20 deletions
|
@ -166,7 +166,7 @@ impl features_t {
|
||||||
/// The special group name "all" may be used for those who like to live on the edge.
|
/// The special group name "all" may be used for those who like to live on the edge.
|
||||||
/// Unknown features are silently ignored.
|
/// Unknown features are silently ignored.
|
||||||
#[widestrs]
|
#[widestrs]
|
||||||
pub fn set_from_string(&mut self, str: wcharz_t) {
|
pub fn set_from_string<'a>(&mut self, str: impl Into<&'a wstr>) {
|
||||||
let str: &wstr = str.into();
|
let str: &wstr = str.into();
|
||||||
let whitespace = "\t\n\0x0B\0x0C\r "L.as_char_slice();
|
let whitespace = "\t\n\0x0B\0x0C\r "L.as_char_slice();
|
||||||
for entry in str.as_char_slice().split(|c| *c == ',') {
|
for entry in str.as_char_slice().split(|c| *c == ',') {
|
||||||
|
@ -232,12 +232,10 @@ pub fn feature_metadata() -> [feature_metadata_t; metadata.len()] {
|
||||||
#[test]
|
#[test]
|
||||||
#[widestrs]
|
#[widestrs]
|
||||||
fn test_feature_flags() {
|
fn test_feature_flags() {
|
||||||
use crate::wchar_ffi::wcharz;
|
|
||||||
|
|
||||||
let mut f = features_t::new();
|
let mut f = features_t::new();
|
||||||
f.set_from_string(wcharz!("stderr-nocaret,nonsense"L));
|
f.set_from_string("stderr-nocaret,nonsense"L);
|
||||||
assert!(f.test(feature_flag_t::stderr_nocaret));
|
assert!(f.test(feature_flag_t::stderr_nocaret));
|
||||||
f.set_from_string(wcharz!("stderr-nocaret,no-stderr-nocaret,nonsense"L));
|
f.set_from_string("stderr-nocaret,no-stderr-nocaret,nonsense"L);
|
||||||
assert!(f.test(feature_flag_t::stderr_nocaret));
|
assert!(f.test(feature_flag_t::stderr_nocaret));
|
||||||
|
|
||||||
// Ensure every metadata is represented once.
|
// Ensure every metadata is represented once.
|
||||||
|
|
|
@ -30,11 +30,11 @@ fn ordering_to_int(ord: Ordering) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wcsfilecmp_glob_ffi(a: wcharz_t, b: wcharz_t) -> i32 {
|
fn wcsfilecmp_glob_ffi(a: wcharz_t, b: wcharz_t) -> i32 {
|
||||||
ordering_to_int(wcsfilecmp_glob(a, b))
|
ordering_to_int(wcsfilecmp_glob(a.into(), b.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wcsfilecmp_ffi(a: wcharz_t, b: wcharz_t) -> i32 {
|
fn wcsfilecmp_ffi(a: wcharz_t, b: wcharz_t) -> i32 {
|
||||||
ordering_to_int(wcsfilecmp(a, b))
|
ordering_to_int(wcsfilecmp(a.into(), b.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compares two wide character strings with an (arguably) intuitive ordering. This function tries
|
/// Compares two wide character strings with an (arguably) intuitive ordering. This function tries
|
||||||
|
@ -64,10 +64,7 @@ fn wcsfilecmp_ffi(a: wcharz_t, b: wcharz_t) -> i32 {
|
||||||
/// a 'file1' and 'File1' will not be considered identical, and hence their internal sort order is
|
/// a 'file1' and 'File1' will not be considered identical, and hence their internal sort order is
|
||||||
/// not arbitrary, but the names 'file1', 'File2' and 'file3' will still be sorted in the order
|
/// not arbitrary, but the names 'file1', 'File2' and 'file3' will still be sorted in the order
|
||||||
/// given above.
|
/// given above.
|
||||||
pub fn wcsfilecmp(a: wcharz_t, b: wcharz_t) -> Ordering {
|
pub fn wcsfilecmp(a: &wstr, b: &wstr) -> Ordering {
|
||||||
// TODO This should return `std::cmp::Ordering`.
|
|
||||||
let a: &wstr = a.into();
|
|
||||||
let b: &wstr = b.into();
|
|
||||||
let mut retval = Ordering::Equal;
|
let mut retval = Ordering::Equal;
|
||||||
let mut ai = 0;
|
let mut ai = 0;
|
||||||
let mut bi = 0;
|
let mut bi = 0;
|
||||||
|
@ -134,10 +131,7 @@ pub fn wcsfilecmp(a: wcharz_t, b: wcharz_t) -> Ordering {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// wcsfilecmp, but frozen in time for glob usage.
|
/// wcsfilecmp, but frozen in time for glob usage.
|
||||||
pub fn wcsfilecmp_glob(a: wcharz_t, b: wcharz_t) -> Ordering {
|
pub fn wcsfilecmp_glob(a: &wstr, b: &wstr) -> Ordering {
|
||||||
// TODO This should return `std::cmp::Ordering`.
|
|
||||||
let a: &wstr = a.into();
|
|
||||||
let b: &wstr = b.into();
|
|
||||||
let mut retval = Ordering::Equal;
|
let mut retval = Ordering::Equal;
|
||||||
let mut ai = 0;
|
let mut ai = 0;
|
||||||
let mut bi = 0;
|
let mut bi = 0;
|
||||||
|
@ -268,14 +262,10 @@ fn wcsfilecmp_leading_digits(a: &wstr, b: &wstr) -> (Ordering, usize, usize) {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_wcsfilecmp() {
|
fn test_wcsfilecmp() {
|
||||||
use crate::wchar::L;
|
use crate::wchar::L;
|
||||||
use crate::wchar_ffi::wcharz;
|
|
||||||
|
|
||||||
macro_rules! validate {
|
macro_rules! validate {
|
||||||
($str1:expr, $str2:expr, $expected_rc:expr) => {
|
($str1:expr, $str2:expr, $expected_rc:expr) => {
|
||||||
assert_eq!(
|
assert_eq!(wcsfilecmp(L!($str1), L!($str2)), $expected_rc)
|
||||||
wcsfilecmp(wcharz!(L!($str1)), wcharz!(L!($str2))),
|
|
||||||
$expected_rc
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue