Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

AcceleratorKeyCodepointTranslator

res.AcceleratorKeyCodepointTranslator
const AcceleratorKeyCodepointTranslator = struct

File

Code

const AcceleratorKeyCodepointTranslator = struct {
    string_type: literals.StringType,
    output_code_page: SupportedCodePage,

    pub fn translate(self: @This(), maybe_parsed: ?literals.IterativeStringParser.ParsedCodepoint) ?u21 {
        const parsed = maybe_parsed orelse return null;
        if (parsed.codepoint == Codepoint.invalid) return 0xFFFD;
        if (parsed.from_escaped_integer) {
            switch (self.string_type) {
                .ascii => {
                    const truncated: u8 = @truncate(parsed.codepoint);
                    switch (self.output_code_page) {
                        .utf8 => switch (truncated) {
                            0...0x7F => return truncated,
                            else => return 0xFFFD,
                        },
                        .windows1252 => return windows1252.toCodepoint(truncated),
                    }
                },
                .wide => {
                    const truncated: u16 = @truncate(parsed.codepoint);
                    return truncated;
                },
            }
        }
        if (parsed.escaped_surrogate_pair) {
            // The codepoint of only the low surrogate
            const low = @as(u16, @intCast(parsed.codepoint & 0x3FF)) + 0xDC00;
            return low;
        }
        return parsed.codepoint;
    }
}