rune/doc/build/
js.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::alloc::{self, String};

/// Encode `string` as part of a quoted javascript string.
pub(crate) fn encode_quoted(out: &mut String, string: &str) -> alloc::Result<()> {
    for c in string.chars() {
        let s = match c {
            '\\' => "\\\\",
            '\"' => "\\\"",
            c => {
                out.try_push(c)?;
                continue;
            }
        };

        out.try_push_str(s)?;
    }

    Ok(())
}