Skip to main content

string_text

Function string_text 

Source
pub fn string_text(text: &str) -> String
Expand description

Escape a string for a Zig string literal.

This module’s own rather than crate::writer::escape_string, because that one writes \0 for a NUL and Zig has no \0 escape: its escapes are \n, \r, \t, \\, \', \", \xNN and \u{…} (Zig language reference, “String Literals and Unicode Code Point Literals”). A NUL in an IDL string constant is legal — IDL 4.2 puts no restriction on a string’s contents — and would otherwise produce a literal no Zig compiler reads.

Everything outside the printable ASCII range that is not one of the named escapes is written \xNN if it is an octet and passed through otherwise: Zig source is UTF-8, so a character above the ASCII range is already what the file should contain.