floem_editor_core/chars.rs
1/// Determine whether a character is a line ending.
2#[inline]
3pub fn char_is_line_ending(ch: char) -> bool {
4 matches!(ch, '\u{000A}')
5}
6
7/// Determine whether a character qualifies as (non-line-break)
8/// whitespace.
9#[inline]
10pub fn char_is_whitespace(ch: char) -> bool {
11 // TODO: this is a naive binary categorization of whitespace
12 // characters. For display, word wrapping, etc. we'll need a better
13 // categorization based on e.g. breaking vs non-breaking spaces
14 // and whether they're zero-width or not.
15 match ch {
16 //'\u{1680}' | // Ogham Space Mark (here for completeness, but usually displayed as a dash, not as whitespace)
17 '\u{0009}' | // Character Tabulation
18 '\u{0020}' | // Space
19 '\u{00A0}' | // No-break Space
20 '\u{180E}' | // Mongolian Vowel Separator
21 '\u{202F}' | // Narrow No-break Space
22 '\u{205F}' | // Medium Mathematical Space
23 '\u{3000}' | // Ideographic Space
24 '\u{FEFF}' // Zero Width No-break Space
25 => true,
26
27 // En Quad, Em Quad, En Space, Em Space, Three-per-em Space,
28 // Four-per-em Space, Six-per-em Space, Figure Space,
29 // Punctuation Space, Thin Space, Hair Space, Zero Width Space.
30 ch if ('\u{2000}' ..= '\u{200B}').contains(&ch) => true,
31
32 _ => false,
33 }
34}