[pbs-devel] [RFC proxmox] support quoted strings in property strings
Fabian Ebner
f.ebner at proxmox.com
Fri Feb 18 09:02:13 CET 2022
> +fn parse_quoted_string<'s>(data: &'_ mut &'s str) -> Result<Cow<'s, str>, Error> {
> + let data_out = data;
> + let data = data_out.as_bytes();
> +
> + if data[0] != b'"' {
> + bail!("not a quoted string");
> + }
> +
> + let mut i = 1;
> + while i != data.len() {
> + if data[i] == b'"' {
What if a byte that's part of an UTF-8 character is equal to b'"', or
can that not happen?
> + // unsafe: we're at an ascii boundary and index [0] is an ascii quote
> + let value = unsafe { std::str::from_utf8_unchecked(&data[1..i]) };
> + *data_out = unsafe { std::str::from_utf8_unchecked(&data[(i + 1)..]) };
> + return Ok(Cow::Borrowed(value));
> + } else if data[i] == b'\\' {
> + // we cannot borrow
> + break;
> + }
> + i += 1;
> + }
More information about the pbs-devel
mailing list