Adopt wstr::split in more places

This simplifies some code that was written before wstr::split existed.
This commit is contained in:
ridiculousfish 2023-04-23 19:34:52 -07:00
parent fa39113bc6
commit d0c902a548
2 changed files with 7 additions and 9 deletions

View File

@ -1,6 +1,7 @@
use crate::ffi::{get_flog_file_fd, wildcard_match};
use crate::parse_util::parse_util_unescape_wildcards;
use crate::wchar::{widestrs, wstr, WString};
use crate::wchar_ext::WExt;
use crate::wchar_ffi::WCharToFFI;
use std::io::Write;
use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
@ -231,11 +232,11 @@ pub fn activate_flog_categories_by_pattern(wc_ptr: &wstr) {
*c = '-';
}
}
for s in wc.as_char_slice().split(|c| *c == ',') {
if s.starts_with(&['-']) {
apply_one_wildcard(wstr::from_char_slice(&s[1..]), false);
for s in wc.split(',') {
if s.starts_with('-') {
apply_one_wildcard(s.slice_from(1), false);
} else {
apply_one_wildcard(wstr::from_char_slice(s), true);
apply_one_wildcard(s, true);
}
}
}

View File

@ -12,6 +12,7 @@ use crate::fallback;
use crate::fds::AutoCloseFd;
use crate::flog::FLOGF;
use crate::wchar::{wstr, WString, L};
use crate::wchar_ext::WExt;
use crate::wcstringutil::{join_strings, split_string, wcs2string_callback};
pub(crate) use gettext::{wgettext, wgettext_fmt};
use libc::{
@ -202,11 +203,7 @@ pub fn normalize_path(path: &wstr, allow_leading_double_slashes: bool) -> WStrin
leading_slashes += 1;
}
let comps = path
.as_char_slice()
.split(|&c| c == sep)
.map(wstr::from_char_slice)
.collect::<Vec<_>>();
let comps: Vec<&wstr> = path.split(sep).collect();
let mut new_comps = Vec::new();
for comp in comps {
if comp.is_empty() || comp == "." {