From 316238f9ea69d646a10d52e012410ebf06def398 Mon Sep 17 00:00:00 2001 From: utox39 Date: Mon, 25 Aug 2025 01:25:59 +0200 Subject: [PATCH] feat(utils): add a utility function to get the length of the longest ascii art row --- src/utils.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/utils.zig b/src/utils.zig index f368d9e..53b45b3 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -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..])); +}