pub struct SfString<'a> { /* private fields */ }Expand description
A String: the content between the quotes, only \" and \\ escapes.
§Examples
use parse_net::sfv::{self, BareItem};
let BareItem::String(s) = sfv::parse_item(b"\"hello\"")?.bare else { unreachable!() };
assert!(s.eq_str("hello"));Implementations§
Source§impl<'a> SfString<'a>
impl<'a> SfString<'a>
Sourcepub const fn raw(&self) -> &'a str
pub const fn raw(&self) -> &'a str
The content as sent, escapes included (ASCII by construction).
§Examples
use parse_net::sfv::{self, BareItem};
let BareItem::String(s) = sfv::parse_item(br#""a\"b""#)?.bare else { unreachable!() };
assert_eq!(s.raw(), r#"a\"b"#);Sourcepub const fn as_plain(&self) -> Option<&'a str>
pub const fn as_plain(&self) -> Option<&'a str>
The value with no copy, when it has no escape.
§Examples
use parse_net::sfv::{self, BareItem};
let BareItem::String(s) = sfv::parse_item(b"\"plain\"")?.bare else { unreachable!() };
assert_eq!(s.as_plain(), Some("plain"));
let BareItem::String(e) = sfv::parse_item(br#""a\"b""#)?.bare else { unreachable!() };
assert_eq!(e.as_plain(), None);Sourcepub fn unescaped_len(&self) -> usize
pub fn unescaped_len(&self) -> usize
The length of the unescaped value.
§Examples
use parse_net::sfv::{self, BareItem};
let BareItem::String(s) = sfv::parse_item(br#""a\"b""#)?.bare else { unreachable!() };
assert_eq!(s.raw().len(), 4);
assert_eq!(s.unescaped_len(), 3);Sourcepub fn unescape_into<'b>(
&self,
out: &'b mut [u8],
) -> Result<&'b str, ParseError>
pub fn unescape_into<'b>( &self, out: &'b mut [u8], ) -> Result<&'b str, ParseError>
Writes the unescaped value into out and returns it.
§Errors
ErrorKind::BufferTooSmall; nothing is written.
§Examples
use parse_net::sfv::{self, BareItem};
let BareItem::String(s) = sfv::parse_item(b"\"a \\\"b\\\"\"")?.bare else { unreachable!() };
let mut buf = [0u8; 8];
assert_eq!(s.unescape_into(&mut buf)?, "a \"b\"");
assert!(s.eq_str("a \"b\""));Trait Implementations§
impl<'a> Copy for SfString<'a>
impl<'a> Eq for SfString<'a>
impl<'a> StructuralPartialEq for SfString<'a>
Auto Trait Implementations§
impl<'a> Forget for SfString<'a>
impl<'a> Freeze for SfString<'a>
impl<'a> RefUnwindSafe for SfString<'a>
impl<'a> Send for SfString<'a>
impl<'a> Sync for SfString<'a>
impl<'a> Unpin for SfString<'a>
impl<'a> UnsafeUnpin for SfString<'a>
impl<'a> UnwindSafe for SfString<'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