feat(utils): add a utility function to get the length of the longest ascii art row

This commit is contained in:
utox39
2025-08-25 01:25:59 +02:00
parent 7ad5181381
commit 316238f9ea

View File

@@ -98,3 +98,19 @@ test "countCodepoints" {
try std.testing.expectEqual(28, try countCodepoints(str));
}
pub fn getLongestAsciiArtRowLen(ascii_art: []const []const u8) !usize {
var longest_len: usize = 0;
for (ascii_art) |ascii_row| {
longest_len = @max(longest_len, try countCodepoints(ascii_row));
}
return longest_len;
}
test "getLongestAsciiArtRowLen" {
const rows = [_][]const u8{ " ████████████████", "██░░░░██████████░░ ░░██████████░░░░██" };
try std.testing.expectEqual(40, try getLongestAsciiArtRowLen(rows[0..]));
}