pub struct Quoted<'a> { /* private fields */ }Expand description
A validated quoted string: the bytes between the quotes, and whether any quoted pair occurs.
Debug prints the raw bytes as an escaped byte string.
§Examples
use parse_net::text;
let (q, _) = text::parse_quoted(b"\"say \\\"hi\\\"\"")?;
assert!(q.has_escapes() && q.as_plain().is_none());
assert_eq!(q.unescaped_len(), 8);
let mut buf = [0u8; 8];
assert_eq!(q.unescape_into(&mut buf)?, b"say \"hi\"");
assert!(q.eq_bytes(b"say \"hi\""));
let mut short = [0u8; 7];
assert_eq!(q.unescape_into(&mut short).unwrap_err().kind(), parse_net::ErrorKind::BufferTooSmall);Implementations§
Source§impl<'a> Quoted<'a>
impl<'a> Quoted<'a>
Sourcepub const fn raw(&self) -> &'a [u8] ⓘ
pub const fn raw(&self) -> &'a [u8] ⓘ
The content between the quotes exactly as sent, quoted pairs included.
Sourcepub const fn has_escapes(&self) -> bool
pub const fn has_escapes(&self) -> bool
Whether the content contains a quoted pair (\x).
Sourcepub const fn as_plain(&self) -> Option<&'a [u8]>
pub const fn as_plain(&self) -> Option<&'a [u8]>
The content when it contains no quoted pair: the value, with no copy.
Sourcepub fn unescaped_len(&self) -> usize
pub fn unescaped_len(&self) -> usize
The length of the value with quoted pairs replaced.
Sourcepub fn unescape_into<'b>(
&self,
out: &'b mut [u8],
) -> Result<&'b [u8], ParseError>
pub fn unescape_into<'b>( &self, out: &'b mut [u8], ) -> Result<&'b [u8], ParseError>
Writes the value into out, every quoted pair replaced by the byte
after the backslash, and returns the written part.
§Errors
ErrorKind::BufferTooSmall when out is shorter than
unescaped_len; nothing is written.
Sourcepub fn eq_bytes(&self, other: &[u8]) -> bool
pub fn eq_bytes(&self, other: &[u8]) -> bool
Whether the value equals other, compared without a buffer.
Sourcepub fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool
pub fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool
Whether the value equals other ignoring ASCII case, compared without
a buffer.
Trait Implementations§
impl<'a> Copy for Quoted<'a>
impl<'a> Eq for Quoted<'a>
impl<'a> StructuralPartialEq for Quoted<'a>
Auto Trait Implementations§
impl<'a> Freeze for Quoted<'a>
impl<'a> RefUnwindSafe for Quoted<'a>
impl<'a> Send for Quoted<'a>
impl<'a> Sync for Quoted<'a>
impl<'a> Unpin for Quoted<'a>
impl<'a> UnsafeUnpin for Quoted<'a>
impl<'a> UnwindSafe for Quoted<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more