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 standard library. Private Function
If last_emitted_code_unit and code_unit form a surrogate pair, then the previously emitted high surrogate is overwritten by the codepoint encoded by the surrogate pair, and null is returned. Otherwise, code_unit is emitted and returned.
fnemitCharacter(self: *Windows, code_unit: u16, last_emitted_code_unit: ?u16) ?u16 {
// Because we are emitting WTF-8, we need to// check to see if we've emitted two consecutive surrogate// codepoints that form a valid surrogate pair in order// to ensure that we're always emitting well-formed WTF-8// (https://wtf-8.codeberg.page/#concatenating).//// If we do have a valid surrogate pair, we need to emit// the UTF-8 sequence for the codepoint that they encode// instead of the WTF-8 encoding for the two surrogate pairs// separately.//// This is relevant when dealing with a WTF-16 encoded// command line like this:// "<0xD801>"<0xDC37>// which would get parsed and converted to WTF-8 as:// <0xED><0xA0><0x81><0xED><0xB0><0xB7>// but instead, we need to recognize the surrogate pair// and emit the codepoint it encodes, which in this// example is U+10437 (𐐷), which is encoded in UTF-8 as:// <0xF0><0x90><0x90><0xB7>if (last_emitted_code_unit != nullandstd.unicode.utf16IsLowSurrogate(code_unit) andstd.unicode.utf16IsHighSurrogate(last_emitted_code_unit.?))
{
constcodepoint = std.unicode.utf16DecodeSurrogatePair(&.{ last_emitted_code_unit.?, code_unit }) catchunreachable;
// Unpaired surrogate is 3 bytes longconstdest = self.buffer[self.end - 3 ..];
constlen = std.unicode.utf8Encode(codepoint, dest) catchunreachable;
// All codepoints that require a surrogate pair (> U+FFFF) are encoded as 4 bytesassert(len == 4);
self.end += 1;
returnnull;
}
constwtf8_len = std.unicode.wtf8Encode(code_unit, self.buffer[self.end..]) catchunreachable;
self.end += wtf8_len;
returncode_unit;
}
If
last_emitted_code_unitandcode_unitform a surrogate pair, then the previously emitted high surrogate is overwritten by the codepoint encoded by the surrogate pair, andnullis returned. Otherwise,code_unitis emitted and returned.