// Copyright june 2026 const std = @import("std"); const unicode = std.unicode; const mem = std.mem; const c = std.c; const wc = @import("wchar"); pub fn width(s: []const u8) !usize { var w: usize = 0; var i: usize = 0; while (i < s.len) { const len = try unicode.utf8ByteSequenceLength(s[i]); const dec = try unicode.utf8Decode(s[i .. i + len]); const cw = wc.wcwidth(@intCast(dec)); if (cw > 0) w += @intCast(cw); i += len; } return w; } test "strwidth" { try std.testing.expectEqual(16, width( \\ へ ♡ ╱|、 )); try std.testing.expectEqual(17, width( \\ ૮ - ՛) (` - 7 )); try std.testing.expectEqual(18, width( \\ / ⁻ ៸| |、⁻〵 )); try std.testing.expectEqual(22, width( \\ 乀(ˍ, ل ل じしˍ,)ノ )); }