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.
§Examples
use parse_net::text::parse_quoted;
let (q, _) = parse_quoted(b"\"a\\\"b\"")?;
assert_eq!(q.raw(), b"a\\\"b");Sourcepub const fn has_escapes(&self) -> bool
pub const fn has_escapes(&self) -> bool
Whether the content contains a quoted pair (\x).
§Examples
use parse_net::text::parse_quoted;
assert!(parse_quoted(b"\"a\\\"b\"")?.0.has_escapes());
assert!(!parse_quoted(b"\"ab\"")?.0.has_escapes());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.
§Examples
use parse_net::text::parse_quoted;
assert_eq!(parse_quoted(b"\"gzip\"")?.0.as_plain(), Some(&b"gzip"[..]));
assert_eq!(parse_quoted(b"\"a\\\"b\"")?.0.as_plain(), None);Sourcepub fn unescaped_len(&self) -> usize
pub fn unescaped_len(&self) -> usize
The length of the value with quoted pairs replaced.
§Examples
use parse_net::text::parse_quoted;
let (q, _) = parse_quoted(b"\"a\\\"b\"")?;
assert_eq!((q.raw().len(), q.unescaped_len()), (4, 3));Sourcepub fn bytes(&self) -> Unescape<'a> ⓘ
pub fn bytes(&self) -> Unescape<'a> ⓘ
The bytes of the value with quoted pairs replaced.
§Examples
use parse_net::text::parse_quoted;
let (q, _) = parse_quoted(b"\"a\\\"b\"")?;
assert_eq!(q.bytes().collect::<Vec<u8>>(), b"a\"b");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.
§Examples
use parse_net::text::parse_quoted;
let (q, _) = parse_quoted(b"\"a\\\"b\"")?;
let mut buf = [0u8; 8];
assert_eq!(q.unescape_into(&mut buf)?, b"a\"b");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.
§Examples
use parse_net::text::parse_quoted;
let (q, _) = parse_quoted(b"\"a\\\"b\"")?;
assert!(q.eq_bytes(b"a\"b") && !q.eq_bytes(b"a\\\"b"));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.
§Examples
use parse_net::text::parse_quoted;
let (q, _) = parse_quoted(b"\"UTF\\-8\"")?;
assert!(q.eq_ignore_ascii_case(b"utf-8") && !q.eq_ignore_ascii_case(b"utf8"));