summaryrefslogtreecommitdiff
path: root/src/DisplayWidth.zig
diff options
context:
space:
mode:
authorGravatar Jose Colon2024-04-11 14:14:42 +0000
committerGravatar Jose Colon2024-04-11 14:14:42 +0000
commit16735685fcc3410de361ba3411788ad1fb4fe188 (patch)
treeaae0199f3d3d3644e06c610cdeeb13f15b377421 /src/DisplayWidth.zig
parentMerge pull request 'grapheme: export grapheme.State struct' (#2) from rockora... (diff)
parentDisplayWidth: explicitly set width to 2 when VS16 is found (diff)
downloadzg-16735685fcc3410de361ba3411788ad1fb4fe188.tar.gz
zg-16735685fcc3410de361ba3411788ad1fb4fe188.tar.xz
zg-16735685fcc3410de361ba3411788ad1fb4fe188.zip
Merge pull request 'DisplayWidth: explicitly set width to 2 when VS16 is found' (#3) from rockorager/zg:vs-16 into master
Reviewed-on: https://codeberg.org/dude_the_builder/zg/pulls/3
Diffstat (limited to 'src/DisplayWidth.zig')
-rw-r--r--src/DisplayWidth.zig4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/DisplayWidth.zig b/src/DisplayWidth.zig
index e547adf..621b8c1 100644
--- a/src/DisplayWidth.zig
+++ b/src/DisplayWidth.zig
@@ -39,6 +39,7 @@ pub fn strWidth(self: Self, str: []const u8) usize {
39 if (cp_iter.next()) |ncp| { 39 if (cp_iter.next()) |ncp| {
40 // emoji text sequence. 40 // emoji text sequence.
41 if (ncp.code == 0xFE0E) w = 1; 41 if (ncp.code == 0xFE0E) w = 1;
42 if (ncp.code == 0xFE0F) w = 2;
42 } 43 }
43 44
44 // Only adding width of first non-zero-width code point. 45 // Only adding width of first non-zero-width code point.
@@ -70,6 +71,9 @@ test "strWidth" {
70 try testing.expectEqual(@as(usize, 2), self.strWidth("\u{26A1}")); // Lone emoji 71 try testing.expectEqual(@as(usize, 2), self.strWidth("\u{26A1}")); // Lone emoji
71 try testing.expectEqual(@as(usize, 1), self.strWidth("\u{26A1}\u{FE0E}")); // Text sequence 72 try testing.expectEqual(@as(usize, 1), self.strWidth("\u{26A1}\u{FE0E}")); // Text sequence
72 try testing.expectEqual(@as(usize, 2), self.strWidth("\u{26A1}\u{FE0F}")); // Presentation sequence 73 try testing.expectEqual(@as(usize, 2), self.strWidth("\u{26A1}\u{FE0F}")); // Presentation sequence
74 try testing.expectEqual(@as(usize, 1), self.strWidth("\u{2764}")); // Default text presentation
75 try testing.expectEqual(@as(usize, 1), self.strWidth("\u{2764}\u{FE0E}")); // Default text presentation with VS15 selector
76 try testing.expectEqual(@as(usize, 2), self.strWidth("\u{2764}\u{FE0F}")); // Default text presentation with VS16 selector
73 try testing.expectEqual(@as(usize, 0), self.strWidth("A\x08")); // Backspace 77 try testing.expectEqual(@as(usize, 0), self.strWidth("A\x08")); // Backspace
74 try testing.expectEqual(@as(usize, 0), self.strWidth("\x7FA")); // DEL 78 try testing.expectEqual(@as(usize, 0), self.strWidth("\x7FA")); // DEL
75 try testing.expectEqual(@as(usize, 0), self.strWidth("\x7FA\x08\x08")); // never less than o 79 try testing.expectEqual(@as(usize, 0), self.strWidth("\x7FA\x08\x08")); // never less than o