feature. See also
. The project being documented here (as the example) is the Zig library itself.
Stringify.outputUnicodeEscape
fn outputUnicodeEscape(codepoint: u21, w: *Writer) Error!void
File
Code
fn outputUnicodeEscape(codepoint: u21, w: *Writer) Error!void {
if (codepoint <= 0xFFFF) {
// then it may be represented as a six-character sequence: a reverse solidus, followed
// by the lowercase letter u, followed by four hexadecimal digits that encode the character's code point.
try w.writeAll("\\u");
try w.printInt(codepoint, 16, .lower, .{ .width = 4, .fill = '0' });
} else {
assert(codepoint <= 0x10FFFF);
// the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair.
const high = @as(u16, @intCast((codepoint - 0x10000) >> 10)) + 0xD800;
const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;
try w.writeAll("\\u");
try w.printInt(high, 16, .lower, .{ .width = 4, .fill = '0' });
try w.writeAll("\\u");
try w.printInt(low, 16, .lower, .{ .width = 4, .fill = '0' });
}
}