From: Fabian Ebner <f.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com, Wolfgang Bumiller <w.bumiller@proxmox.com>
Subject: Re: [pbs-devel] [RFC proxmox] support quoted strings in property strings
Date: Fri, 18 Feb 2022 09:02:13 +0100 [thread overview]
Message-ID: <908fbf5c-a233-24e7-17b8-675e6761050d@proxmox.com> (raw)
In-Reply-To: <20220216133917.101133-1-w.bumiller@proxmox.com>
> +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;
> + }
next prev parent reply other threads:[~2022-02-18 8:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-16 13:39 Wolfgang Bumiller
2022-02-17 8:58 ` Fabian Ebner
2022-02-17 9:47 ` Wolfgang Bumiller
2022-02-17 11:13 ` [pbs-devel] applied: " Thomas Lamprecht
2022-02-18 8:02 ` Fabian Ebner [this message]
2022-02-18 8:13 [pbs-devel] " Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=908fbf5c-a233-24e7-17b8-675e6761050d@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=w.bumiller@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox