diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:29:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:16:28 -0300 |
| commit | 2aa1801dbad2a26348aef085d9dee8096f8d2eb3 (patch) | |
| tree | e35fdd75a346758c770d58c2afd1c112504ed908 /src | |
| parent | abeccae181403d8db145a3c5f72c77648d325b53 (diff) | |
| download | pardes-2aa1801dbad2a26348aef085d9dee8096f8d2eb3.tar.gz pardes-2aa1801dbad2a26348aef085d9dee8096f8d2eb3.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
| -rw-r--r-- | src/modal.zig | 27 |
1 files changed, 11 insertions, 16 deletions
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" { |
