1
0
Fork 0
forked from wry/wry

utils: remove AsciiTrim trait

This commit is contained in:
Julian Orth 2025-01-06 20:09:33 +01:00
parent 0d1aeeab45
commit 32cb00444b
7 changed files with 22 additions and 53 deletions

View file

@ -1,12 +1,9 @@
use {
crate::{
gfx_apis::gl::{
egl::sys::{EGLDisplay, EGL_EXTENSIONS},
gl::sys::GL_EXTENSIONS,
sys::{EGL, GLESV2},
RenderError,
},
utils::trim::AsciiTrim,
crate::gfx_apis::gl::{
egl::sys::{EGLDisplay, EGL_EXTENSIONS},
gl::sys::GL_EXTENSIONS,
sys::{EGL, GLESV2},
RenderError,
},
ahash::AHashSet,
bstr::ByteSlice,
@ -21,7 +18,7 @@ unsafe fn get_extensions(ext: *const c::c_char) -> Option<AHashSet<String>> {
let mut res = AHashSet::new();
let ext = unsafe { CStr::from_ptr(ext).to_bytes() };
for part in ext.split_str(" ") {
let name = part.trim();
let name = part.trim_ascii();
if name.len() > 0 {
if let Ok(s) = str::from_utf8(name) {
res.insert(s.to_string());

View file

@ -22,7 +22,7 @@ use {
},
},
udev::UdevError,
utils::{errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt, trim::AsciiTrim},
utils::{errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt},
},
bstr::ByteSlice,
isnt::std_1::primitive::IsntConstPtrExt,
@ -182,5 +182,9 @@ unsafe extern "C" fn jay_libinput_log_handler(
LIBINPUT_LOG_PRIORITY_ERROR => log::Level::Error,
_ => log::Level::Error,
};
log::log!(priority, "libinput: {}", str.to_bytes().trim().as_bstr());
log::log!(
priority,
"libinput: {}",
str.to_bytes().trim_ascii().as_bstr()
);
}

View file

@ -57,7 +57,6 @@ pub mod timer;
pub mod toplevel_identifier;
pub mod transform_ext;
pub mod tri;
pub mod trim;
pub mod unlink_on_drop;
pub mod vec_ext;
pub mod vecdeque_ext;

View file

@ -1,5 +1,5 @@
use {
crate::utils::{errorfmt::ErrorFmt, oserror::OsError, trim::AsciiTrim},
crate::utils::{errorfmt::ErrorFmt, oserror::OsError},
bstr::ByteSlice,
uapi::{c, OwnedFd},
};
@ -12,7 +12,7 @@ pub struct PidInfo {
pub fn get_pid_info(uid: c::uid_t, pid: c::pid_t) -> PidInfo {
let comm = match std::fs::read(format!("/proc/{}/comm", pid)) {
Ok(name) => name.trim().as_bstr().to_string(),
Ok(name) => name.trim_ascii_end().as_bstr().to_string(),
Err(e) => {
log::warn!("Could not read `comm` of pid {}: {}", pid, ErrorFmt(e));
"Unknown".to_string()

View file

@ -1,33 +0,0 @@
pub trait AsciiTrim {
fn trim(&self) -> &[u8];
fn trim_start(&self) -> &[u8];
fn trim_end(&self) -> &[u8];
}
impl AsciiTrim for [u8] {
fn trim(&self) -> &[u8] {
self.trim_start().trim_end()
}
fn trim_start(&self) -> &[u8] {
let mut s = self;
while let Some((b, r)) = s.split_first() {
if !matches!(*b, b' ' | b'\t' | b'\n') {
break;
}
s = r;
}
s
}
fn trim_end(&self) -> &[u8] {
let mut s = self;
while let Some((b, r)) = s.split_last() {
if !matches!(*b, b' ' | b'\t' | b'\n') {
break;
}
s = r;
}
s
}
}

View file

@ -3,7 +3,7 @@
use {
crate::{
utils::{bitflags::BitflagsExt, oserror::OsError, trim::AsciiTrim},
utils::{bitflags::BitflagsExt, oserror::OsError},
video::drm::{
DrmBlob, DrmCardResources, DrmConnector, DrmConnectorInfo, DrmCrtc, DrmEncoder,
DrmEncoderInfo, DrmError, DrmFb, DrmModeInfo, DrmPlane, DrmPlaneInfo, DrmProperty,
@ -163,7 +163,7 @@ pub fn get_device_name_from_fd2(fd: c::c_int) -> Result<Ustring, OsError> {
break;
}
if let Some(pf) = buf.strip_prefix(b"DEVNAME=") {
return Ok(uapi::format_ustr!("/dev/{}", pf.trim_end().as_bstr()));
return Ok(uapi::format_ustr!("/dev/{}", pf.trim_ascii_end().as_bstr()));
}
}
Err(OsError(c::ENOENT))

View file

@ -6,9 +6,7 @@ include!(concat!(env!("OUT_DIR"), "/xkbcommon_tys.rs"));
pub use consts::*;
use {
crate::utils::{
errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt, trim::AsciiTrim, vecset::VecSet,
},
crate::utils::{errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt, vecset::VecSet},
bstr::{BStr, ByteSlice},
isnt::std_1::primitive::IsntConstPtrExt,
std::{
@ -423,5 +421,9 @@ unsafe extern "C" fn jay_xkbcommon_log_handler(
XKB_LOG_LEVEL_DEBUG => log::Level::Debug,
_ => log::Level::Error,
};
log::log!(level, "xkbcommon: {}", buf.to_bytes().trim_end().as_bstr());
log::log!(
level,
"xkbcommon: {}",
buf.to_bytes().trim_ascii_end().as_bstr(),
);
}