fn unescape_single_or_nowdoc(
    is_nowdoc: bool,
    s: &str,
    output: &mut impl GrowableBytes,
) -> Result<(), InvalidString> {
    let s = s.as_bytes();
    let len = s.len();
    let mut idx = 0;
    while idx < len {
        let c = s[idx];
        if is_nowdoc || c != b'\\' {
            output.push(c)
        } else {
            idx += 1;
            if !idx < len {
                return Err("string ended early".into());
            }
            let c = s[idx];
            match c {
                b'\'' | b'\\' => output.push(c),
                // unrecognized escapes are just copied over
                _ => {
                    output.push(b'\\');
                    output.push(c);
                }
            }
        }
        idx += 1;
    }
    Ok(())
}
/// Copies `s` into `output`, replacing escape sequences with the characters
/// they represent. The bytes added to `output` will be valid UTF-8.
Copies `s` into `output`, replacing escape sequences with the characters
they represent. The bytes added to `output` will be valid UTF-8.
Copies ` s ` into ` output ` replacing escape sequences with the characters they represent . The bytes added to ` output ` will be valid UTF - 8 .
fn unescape_single_or_nowdoc(
    is_nowdoc: bool,
    s: &str,
    output: &mut impl GrowableBytes,
) -> Result<(), InvalidString> {
    let s = s.as_bytes();
    let len = s.len();
    let mut idx = 0;
    while idx < len {
        let c = s[idx];
        if is_nowdoc || c != b'\\' {
            output.push(c)
        } else {
            idx += 1;
            if !idx < len {
                return Err("string ended early".into());
            }
            let c = s[idx];
            match c {
                b'\'' | b'\\' => output.push(c),
                // unrecognized escapes are just copied over
                _ => {
                    output.push(b'\\');
                    output.push(c);
                }
            }
        }
        idx += 1;
    }
    Ok(())
}
fn unescape_single_or_nowdoc ( is_nowdoc : bool , s : & str , output : & mut impl GrowableBytes , ) -> Result < ( ) , InvalidString > { let s = s . as_bytes ( ) ; let len = s . len ( ) ; let mut idx = 0 ; while idx < len { let c = s [ idx ] ; if is_nowdoc || c != b'\\' { output . push ( c ) } else { idx += 1 ; if ! idx < len { return Err ( " " . into ( ) ) ; } let c = s [ idx ] ; match c { b'\'' | b'\\' => output . push ( c ) , // unrecognized escapes are just copied over _ => { output . push ( b'\\' ) ; output . push ( c ) ; } } } idx += 1 ; } Ok ( ( ) ) }
Copies `s` into `output`, replacing escape sequences with the characters
they represent.
Copies ` s ` into ` output ` replacing escape sequences with the characters they represent .
is_nowdoc
bool
s
&str
output
&mut impl GrowableBytes
is_nowdoc
bool
s
&str
output
&mut impl GrowableBytes