pub fn to_content<'a, Spec: GeneralQSSpec>(
    quoted_string: &'a str
) -> Result<Cow<'a, str>, CoreError>
{
    let mut automaton = ScanAutomaton::<Spec::Parsing>::new();
    let mut continue_copy_from = None;
    for (idx, bch) in quoted_string.bytes().enumerate() {
        let emit = automaton.advance(PartialCodePoint::from_utf8_byte(bch))?;
        if !emit {
            continue_copy_from = Some(idx);
            break;
        }
    }

    if let Some(idx) = continue_copy_from {
        let mut buffer = Vec::with_capacity(quoted_string.len()-2);
        buffer.extend_from_slice(&quoted_string.as_bytes()[0..idx]);

        //SLICE_SAFE: we slice bytes so it's safe
        for bch in &quoted_string.as_bytes()[idx+1..] {
            let emit = automaton.advance(PartialCodePoint::from_utf8_byte(*bch))?;
            if emit {
                buffer.push(*bch)
            }
        }

        automaton.end()?;

        //OPTIMIZE: find a way to make sure we can't brake utf8 with emit while still being
        // byte based then use `from_utf8_unchecked`
        // Way 1: check if bch is > 127 if so make sure following UTF8_CONT's are treated the same.
        //        - needs special handling for the first non emited byte
        //        - per iter either a is `> 127` or a `& CONT_MASK == CONT_MASK` which can brake
        //          branch prediction
        //        + we can skip calling `automaton.advance(bch)` for all continuation bytes
        let strfied = String::from_utf8(buffer)
            .expect("[BUG] automaton caused a code point to be only partially emitted");

        Ok(Cow::Owned(strfied))

    } else {
        automaton.end()?;
        let len = quoted_string.len();
        Ok(Cow::Borrowed(&quoted_string[1..len-1]))
    }

}
/// converts a quoted string into it's content
///
/// This methods retrieves the content of a quoted-string, which means it strips the
/// surrounding `'"'`-quoted, converts quoted-pairs into the values they represent and
/// strips not-semantic character.
///
/// # Example
/// ```
/// # use std::borrow::Cow;
/// //use your own Spec in practise
/// use quoted_string::test_utils::TestSpec;
/// use quoted_string::to_content;
///
/// let content = to_content::<TestSpec>("\"ab\\\"c\n\nde\"")
///     .expect("only fails if the input is not a quoted string");
/// assert_eq!(&*content, "ab\"cde");
///
/// let content = to_content::<TestSpec>("\"simple\"").unwrap();
/// // to content will just use slicing to strip `'"'`-quotes if possible
/// assert_eq!(content, Cow::Borrowed("simple"));
/// ```
///
converts a quoted string into it's content
This methods retrieves the content of a quoted-string, which means it strips the
surrounding `'"'`-quoted, converts quoted-pairs into the values they represent and
strips not-semantic character.
converts a quoted string into it ' s content This methods retrieves the content of a quoted - string which means it strips the surrounding ` ' " ' ` - quoted converts quoted - pairs into the values they represent and strips not - semantic character .
pub fn to_content<'a, Spec: GeneralQSSpec>(
    quoted_string: &'a str
) -> Result<Cow<'a, str>, CoreError>
{
    let mut automaton = ScanAutomaton::<Spec::Parsing>::new();
    let mut continue_copy_from = None;
    for (idx, bch) in quoted_string.bytes().enumerate() {
        let emit = automaton.advance(PartialCodePoint::from_utf8_byte(bch))?;
        if !emit {
            continue_copy_from = Some(idx);
            break;
        }
    }
    if let Some(idx) = continue_copy_from {
        let mut buffer = Vec::with_capacity(quoted_string.len()-2);
        buffer.extend_from_slice(&quoted_string.as_bytes()[0..idx]);
        //SLICE_SAFE: we slice bytes so it's safe
        for bch in &quoted_string.as_bytes()[idx+1..] {
            let emit = automaton.advance(PartialCodePoint::from_utf8_byte(*bch))?;
            if emit {
                buffer.push(*bch)
            }
        }
        automaton.end()?;
        //OPTIMIZE: find a way to make sure we can't brake utf8 with emit while still being
        // byte based then use `from_utf8_unchecked`
        // Way 1: check if bch is > 127 if so make sure following UTF8_CONT's are treated the same.
        //        - needs special handling for the first non emited byte
        //        - per iter either a is `> 127` or a `& CONT_MASK == CONT_MASK` which can brake
        //          branch prediction
        //        + we can skip calling `automaton.advance(bch)` for all continuation bytes
        let strfied = String::from_utf8(buffer)
            .expect("[BUG] automaton caused a code point to be only partially emitted");
        Ok(Cow::Owned(strfied))
    } else {
        automaton.end()?;
        let len = quoted_string.len();
        Ok(Cow::Borrowed(&quoted_string[1..len-1]))
    }
}
pub fn to_content < ' a , Spec : GeneralQSSpec > ( quoted_string : & ' a str ) -> Result < Cow < ' a , str > , CoreError > { let mut automaton = ScanAutomaton :: < Spec :: Parsing > :: new ( ) ; let mut continue_copy_from = None ; for ( idx , bch ) in quoted_string . bytes ( ) . enumerate ( ) { let emit = automaton . advance ( PartialCodePoint :: from_utf8_byte ( bch ) ) ? ; if ! emit { continue_copy_from = Some ( idx ) ; break ; } } if let Some ( idx ) = continue_copy_from { let mut buffer = Vec :: with_capacity ( quoted_string . len ( ) - 2 ) ; buffer . extend_from_slice ( & quoted_string . as_bytes ( ) [ 0 .. idx ] ) ; //SLICE_SAFE: we slice bytes so it's safe for bch in & quoted_string . as_bytes ( ) [ idx + 1 .. ] { let emit = automaton . advance ( PartialCodePoint :: from_utf8_byte ( * bch ) ) ? ; if emit { buffer . push ( * bch ) } } automaton . end ( ) ? ; //OPTIMIZE: find a way to make sure we can't brake utf8 with emit while still being // byte based then use `from_utf8_unchecked` // Way 1: check if bch is > 127 if so make sure following UTF8_CONT's are treated the same. //        - needs special handling for the first non emited byte //        - per iter either a is `> 127` or a `& CONT_MASK == CONT_MASK` which can brake //          branch prediction //        + we can skip calling `automaton.advance(bch)` for all continuation bytes let strfied = String :: from_utf8 ( buffer ) . expect ( " " ) ; Ok ( Cow :: Owned ( strfied ) ) } else { automaton . end ( ) ? ; let len = quoted_string . len ( ) ; Ok ( Cow :: Borrowed ( & quoted_string [ 1 .. len - 1 ] ) ) } }
converts a quoted string into it's content
This methods retrieves the content of a quoted-string, which means it strips the
surrounding `'"'`-quoted, converts quoted-pairs into the values they represent and
strips not-semantic character.
converts a quoted string into it ' s content This methods retrieves the content of a quoted - string which means it strips the surrounding ` ' " ' ` - quoted converts quoted - pairs into the values they represent and strips not - semantic character .
quoted_string
&'a str
quoted_string
&'a str
example
None
use std::borrow::cow;


let content = to_content::("\"ab\\\"c\n\nde\"")
.expect("only fails if the input is not a quoted string");
assert_eq!(&*content, "ab\"cde").

let content = to_content::("\"simple\"").unwrap();
to content will just use slicing to strip `'"'`-quotes if possible
assert_eq!(content, Cow::Borrowed("simple"));
```
let content = to_content :: ( " \ " ab \\\ " c \ n \ nde \ " " ) . expect ( " only fails if the input is not a quoted string " ) ; assert_eq! ( & * content " ab \ " cde " ) . let content = to_content :: ( " \ " simple \ " " ) . unwrap () ; to content will just use slicing to strip ` ' " ' ` - quotes if possible assert_eq! ( content Cow :: Borrowed ( " simple " )) ; ` ` `