Skip to main content

encode_script_single_quoted_text_to_vec

Function encode_script_single_quoted_text_to_vec 

Source
pub fn encode_script_single_quoted_text_to_vec<S: AsRef<str>>(
    text: S,
    output: &mut Vec<u8>,
) -> &[u8] ⓘ
Expand description

Encode content of a single-quoted JavaScript string to a mutable Vec<u8> and return the new data slice.

This appends to output and returns only the new data slice.

The input is raw text; existing escapes are encoded as text. The output is string content and does not include outer quotes. Backslashes and ' are escaped with a backslash. < and C0 controls use \xHH with uppercase hex digits. U+2028 and U+2029 use \u2028 and \u2029. Use the output in a JavaScript string inside <script>, not in a template literal or an HTML attribute.