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.
constWindowsEnvironStrings = struct {
PATH: ?[:0]constu16 = null,
PATHEXT: ?[:0]constu16 = null,
fnscan() WindowsEnvironStrings {
constpeb = windows.peb();
assert(windows.ntdll.RtlEnterCriticalSection(peb.FastPebLock) == .SUCCESS);
deferassert(windows.ntdll.RtlLeaveCriticalSection(peb.FastPebLock) == .SUCCESS);
constptr = peb.ProcessParameters.Environment;
varresult: WindowsEnvironStrings = .{};
vari: usize = 0;
while (ptr[i] != 0) {
constkey_start = i;
// There are some special environment variables that start with =,
// so we need a special case to not treat = as a key/value separator
// if it's the first character.
// https://devblogs.microsoft.com/oldnewthing/20100506-00/?p=14133
if (ptr[key_start] == '=') i += 1;
while (ptr[i] != 0andptr[i] != '=') : (i += 1) {}
constkey_w = ptr[key_start..i];
if (ptr[i] == '=') i += 1;
constvalue_start = i;
while (ptr[i] != 0) : (i += 1) {}
constvalue_w = ptr[value_start..i :0];
i += 1; // skip over null byteinlinefor (@typeInfo(WindowsEnvironStrings).@"struct".field_names) |field_name| {
constfield_name_w = comptimestd.unicode.wtf8ToWtf16LeStringLiteral(field_name);
if (windows.eqlIgnoreCaseWtf16(key_w, field_name_w)) @field(result, field_name) = value_w;
}
}
returnresult;
}
}