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.

filepathWithExtension

cli.filepathWithExtension
pub fn filepathWithExtension(allocator: Allocator, path: []const u8, ext: []const u8) ![]const u8

File

Code

pub fn filepathWithExtension(allocator: Allocator, path: []const u8, ext: []const u8) ![]const u8 {
    var buf: std.ArrayList(u8) = .empty;
    errdefer buf.deinit(allocator);
    if (std.fs.path.dirname(path)) |dirname| {
        var end_pos = dirname.len;
        // We want to ensure that we write a path separator at the end, so if the dirname
        // doesn't end with a path sep then include the char after the dirname
        // which must be a path sep.
        if (!std.fs.path.isSep(dirname[dirname.len - 1])) end_pos += 1;
        try buf.appendSlice(allocator, path[0..end_pos]);
    }
    try buf.appendSlice(allocator, std.fs.path.stem(path));
    try buf.appendSlice(allocator, ext);
    return try buf.toOwnedSlice(allocator);
}