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.
pubfntagToId(tag: []constu8) error{InvalidLanguageTag}!?LanguageId {
constparsed = tryparse(tag);
// There are currently no language tags with assigned IDs that have
// multiple suffixes, so we can skip the lookup.
if (parsed.multiple_suffixes) returnnull;
constlongest_known_tag = comptimeblk: {
varlen = 0;
for (@typeInfo(LanguageId).@"enum".field_names) |field_name| {
if (field_name.len > len) len = field_name.len;
}
break :blklen;
};
// If the tag is longer than the longest tag that has an assigned ID,
// then we can skip the lookup.
if (tag.len > longest_known_tag) returnnull;
varnormalized_buf: [longest_known_tag]u8 = undefined;
// To allow e.g. `de-de_phoneb` to get looked up as `de-de`, we need to
// omit the suffix, but only if the tag contains a valid alternate sort order.
consttag_to_normalize = if (parsed.isSuffixValidSortOrder()) tag[0 .. tag.len - (parsed.suffix.?.len + 1)] elsetag;
constnormalized_tag = normalizeTag(tag_to_normalize, &normalized_buf);
returnstd.meta.stringToEnum(LanguageId, normalized_tag) orelse {
// special case for a tag that has been mapped to the same ID
// twice.
if (std.mem.eql(u8, "ff_latn_ng", normalized_tag)) {
returnLanguageId.ff_ng;
}
returnnull;
};
}