From 2aa1801dbad2a26348aef085d9dee8096f8d2eb3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:29:32 -0300 Subject: modal: kindOfCodepoint answers the WordClass wordClassAt returns, and the Kind enum and the switch between the two go Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/modal.zig | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/modal.zig b/src/modal.zig index 0a61e920..8a611691 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -751,9 +751,6 @@ pub const Cursor = struct { } }; -// Unicode word characters, punctuation, and whitespace. -pub const Kind = enum { word, punct, ws }; - fn codepointAt(text: []const u8, off: usize) u21 { if (off >= text.len) return 0xFFFD; const n = std.unicode.utf8ByteSequenceLength(text[off]) catch return 0xFFFD; @@ -769,7 +766,9 @@ pub fn isUnicodeWhitespace(cp: u21) bool { }; } -fn kindOfCodepoint(cp: u21) Kind { +/// A codepoint's word class: Unicode word characters, punctuation, or +/// whitespace (line ends included; wordClassAt tells them apart). +fn kindOfCodepoint(cp: u21) WordClass { if (isUnicodeWhitespace(cp)) return .ws; if (cp == '_') return .word; return switch (uucode.get(.general_category, cp)) { @@ -1449,11 +1448,7 @@ fn wordClassAt(text: []const u8, off: usize) WordClass { if (off >= text.len) return .eol; const cp = codepointAt(text, off); if (cp == '\n' or cp == '\r') return .eol; - return switch (kindOfCodepoint(cp)) { - .word => .word, - .punct => .punct, - .ws => .ws, - }; + return kindOfCodepoint(cp); } pub fn searchWordAt(text: []const u8, off: usize) bool { @@ -2060,13 +2055,13 @@ test "decimal increment preserves padding and handles sign changes" { } test "codepoint classes distinguish words punctuation and whitespace" { - try std.testing.expectEqual(Kind.word, kindOfCodepoint('a')); - try std.testing.expectEqual(Kind.word, kindOfCodepoint('_')); - try std.testing.expectEqual(Kind.word, kindOfCodepoint('9')); - try std.testing.expectEqual(Kind.punct, kindOfCodepoint('.')); - try std.testing.expectEqual(Kind.punct, kindOfCodepoint('(')); - try std.testing.expectEqual(Kind.ws, kindOfCodepoint(' ')); - try std.testing.expectEqual(Kind.ws, kindOfCodepoint('\n')); + try std.testing.expectEqual(WordClass.word, kindOfCodepoint('a')); + try std.testing.expectEqual(WordClass.word, kindOfCodepoint('_')); + try std.testing.expectEqual(WordClass.word, kindOfCodepoint('9')); + try std.testing.expectEqual(WordClass.punct, kindOfCodepoint('.')); + try std.testing.expectEqual(WordClass.punct, kindOfCodepoint('(')); + try std.testing.expectEqual(WordClass.ws, kindOfCodepoint(' ')); + try std.testing.expectEqual(WordClass.ws, kindOfCodepoint('\n')); } test "insert cursor steps characters" { -- cgit v1.3