Function torut::utils::unquote_string[][src]

pub fn unquote_string(
    text: &str
) -> (Option<usize>, Result<Cow<'_, str>, UnquoteStringError>)
Expand description

unquote_string performs string unquoting According to torCP docs it parses QuotedString token.

Note

In order to be quoted text MUST start with ‘“’ char(no white chars allowed).

When quoted?

String is considered quoted when it starts with quote and contains at least one unescaped quote after first one. Please note that above implies that first 3 chars out of 100 char string may be used to construct it.

Return value

If string is not quoted or no escape sequences are in use borrowed cow is returned. If quoted string does not use any escape sequences borrowed cow is returned. If string uses escape sequences which give valid utf8 string owned cow is returned. If quoted string is longer than entire text Otherwise error is returned This function does not if content of quotes is valid utf8/is single line or if it does contains any sequence considered as invalid when looking at standard this implies that return value MAY contain non-ascii chars OR zero bytes. It’s caller responsibility to filter them if needed.

Second returned offset(first returned one) value is Some only when string is quoted. It returns byte offset of last char consumed in string unquoting. Using text.as_bytes()[idx] where idx is given value should yield ‘“’ char.