utils: remove AsciiTrim trait
This commit is contained in:
parent
0d1aeeab45
commit
32cb00444b
7 changed files with 22 additions and 53 deletions
|
|
@ -1,12 +1,9 @@
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::gfx_apis::gl::{
|
||||||
gfx_apis::gl::{
|
egl::sys::{EGLDisplay, EGL_EXTENSIONS},
|
||||||
egl::sys::{EGLDisplay, EGL_EXTENSIONS},
|
gl::sys::GL_EXTENSIONS,
|
||||||
gl::sys::GL_EXTENSIONS,
|
sys::{EGL, GLESV2},
|
||||||
sys::{EGL, GLESV2},
|
RenderError,
|
||||||
RenderError,
|
|
||||||
},
|
|
||||||
utils::trim::AsciiTrim,
|
|
||||||
},
|
},
|
||||||
ahash::AHashSet,
|
ahash::AHashSet,
|
||||||
bstr::ByteSlice,
|
bstr::ByteSlice,
|
||||||
|
|
@ -21,7 +18,7 @@ unsafe fn get_extensions(ext: *const c::c_char) -> Option<AHashSet<String>> {
|
||||||
let mut res = AHashSet::new();
|
let mut res = AHashSet::new();
|
||||||
let ext = unsafe { CStr::from_ptr(ext).to_bytes() };
|
let ext = unsafe { CStr::from_ptr(ext).to_bytes() };
|
||||||
for part in ext.split_str(" ") {
|
for part in ext.split_str(" ") {
|
||||||
let name = part.trim();
|
let name = part.trim_ascii();
|
||||||
if name.len() > 0 {
|
if name.len() > 0 {
|
||||||
if let Ok(s) = str::from_utf8(name) {
|
if let Ok(s) = str::from_utf8(name) {
|
||||||
res.insert(s.to_string());
|
res.insert(s.to_string());
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ use {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
udev::UdevError,
|
udev::UdevError,
|
||||||
utils::{errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt, trim::AsciiTrim},
|
utils::{errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt},
|
||||||
},
|
},
|
||||||
bstr::ByteSlice,
|
bstr::ByteSlice,
|
||||||
isnt::std_1::primitive::IsntConstPtrExt,
|
isnt::std_1::primitive::IsntConstPtrExt,
|
||||||
|
|
@ -182,5 +182,9 @@ unsafe extern "C" fn jay_libinput_log_handler(
|
||||||
LIBINPUT_LOG_PRIORITY_ERROR => log::Level::Error,
|
LIBINPUT_LOG_PRIORITY_ERROR => log::Level::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()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,6 @@ pub mod timer;
|
||||||
pub mod toplevel_identifier;
|
pub mod toplevel_identifier;
|
||||||
pub mod transform_ext;
|
pub mod transform_ext;
|
||||||
pub mod tri;
|
pub mod tri;
|
||||||
pub mod trim;
|
|
||||||
pub mod unlink_on_drop;
|
pub mod unlink_on_drop;
|
||||||
pub mod vec_ext;
|
pub mod vec_ext;
|
||||||
pub mod vecdeque_ext;
|
pub mod vecdeque_ext;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use {
|
use {
|
||||||
crate::utils::{errorfmt::ErrorFmt, oserror::OsError, trim::AsciiTrim},
|
crate::utils::{errorfmt::ErrorFmt, oserror::OsError},
|
||||||
bstr::ByteSlice,
|
bstr::ByteSlice,
|
||||||
uapi::{c, OwnedFd},
|
uapi::{c, OwnedFd},
|
||||||
};
|
};
|
||||||
|
|
@ -12,7 +12,7 @@ pub struct PidInfo {
|
||||||
|
|
||||||
pub fn get_pid_info(uid: c::uid_t, pid: c::pid_t) -> 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)) {
|
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) => {
|
Err(e) => {
|
||||||
log::warn!("Could not read `comm` of pid {}: {}", pid, ErrorFmt(e));
|
log::warn!("Could not read `comm` of pid {}: {}", pid, ErrorFmt(e));
|
||||||
"Unknown".to_string()
|
"Unknown".to_string()
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
utils::{bitflags::BitflagsExt, oserror::OsError, trim::AsciiTrim},
|
utils::{bitflags::BitflagsExt, oserror::OsError},
|
||||||
video::drm::{
|
video::drm::{
|
||||||
DrmBlob, DrmCardResources, DrmConnector, DrmConnectorInfo, DrmCrtc, DrmEncoder,
|
DrmBlob, DrmCardResources, DrmConnector, DrmConnectorInfo, DrmCrtc, DrmEncoder,
|
||||||
DrmEncoderInfo, DrmError, DrmFb, DrmModeInfo, DrmPlane, DrmPlaneInfo, DrmProperty,
|
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;
|
break;
|
||||||
}
|
}
|
||||||
if let Some(pf) = buf.strip_prefix(b"DEVNAME=") {
|
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))
|
Err(OsError(c::ENOENT))
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@ include!(concat!(env!("OUT_DIR"), "/xkbcommon_tys.rs"));
|
||||||
|
|
||||||
pub use consts::*;
|
pub use consts::*;
|
||||||
use {
|
use {
|
||||||
crate::utils::{
|
crate::utils::{errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt, vecset::VecSet},
|
||||||
errorfmt::ErrorFmt, oserror::OsError, ptr_ext::PtrExt, trim::AsciiTrim, vecset::VecSet,
|
|
||||||
},
|
|
||||||
bstr::{BStr, ByteSlice},
|
bstr::{BStr, ByteSlice},
|
||||||
isnt::std_1::primitive::IsntConstPtrExt,
|
isnt::std_1::primitive::IsntConstPtrExt,
|
||||||
std::{
|
std::{
|
||||||
|
|
@ -423,5 +421,9 @@ unsafe extern "C" fn jay_xkbcommon_log_handler(
|
||||||
XKB_LOG_LEVEL_DEBUG => log::Level::Debug,
|
XKB_LOG_LEVEL_DEBUG => log::Level::Debug,
|
||||||
_ => log::Level::Error,
|
_ => 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(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue