use super::*;
impl Line<'static> {
pub fn new_realname() -> Option<Self> {
#[cfg(feature = "whoami")]
if let Ok(val) = Line::from_bytes(whoami::realname()) {
return Some(val);
}
None
}
}
impl Key<'_> {
pub fn is_client_tag(&self) -> bool {
unsafe { *self.0.get_unchecked(0) == b'+' }
}
}
impl User<'static> {
pub fn new_username() -> Option<Self> {
#[cfg(feature = "whoami")]
if let Ok(val) = User::from_bytes(whoami::username()) {
return Some(val);
}
None
}
pub fn from_id(id: u32) -> Self {
let retval = format!("i{id:08x}");
User::from_bytes(retval).unwrap()
}
pub fn from_id_short(id: u16) -> Self {
let retval = format!("i{id:05}");
User::from_bytes(retval).unwrap()
}
}
impl<'a> Cmd<'a> {
pub fn from_word(word: impl Into<Word<'a>>) -> Result<Self, InvalidString> {
let mut word = word.into();
if let Some(inval) = word.iter().find(|b| !b.is_ascii_alphabetic()) {
return Err(InvalidString::Byte(*inval));
};
word.transform(AsciiCasemap::<true>);
Ok(unsafe { Cmd::from_unchecked(word.into()) })
}
pub const fn as_str(&self) -> &str {
unsafe { std::str::from_utf8_unchecked(self.0.as_bytes()) }
}
}