aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorNathan Vegdahl2021-06-14 02:13:31 +0000
committerNathan Vegdahl2021-06-15 01:32:23 +0000
commit0a5580aa21b55947859191a4f33244d77fb794ed (patch)
treef93dc151c4848781268f0888666c9a1bc29a080f /helix-core
parent358ea6a37ccc3ee98f3680c9b4ee0dd0aa0781d2 (diff)
Address PR comments.
- Move char functions into their own module under helix_core. - Use matches!() macro where appropriate. - Use a static lifetime on indent_unit() now that we can.
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/chars.rs41
-rw-r--r--helix-core/src/lib.rs1
2 files changed, 42 insertions, 0 deletions
diff --git a/helix-core/src/chars.rs b/helix-core/src/chars.rs
new file mode 100644
index 00000000..243a1374
--- /dev/null
+++ b/helix-core/src/chars.rs
@@ -0,0 +1,41 @@
+/// Determine whether a character is a line break.
+pub fn char_is_linebreak(c: char) -> bool {
+ matches!(
+ c,
+ '\u{000A}' | // LineFeed
+ '\u{000B}' | // VerticalTab
+ '\u{000C}' | // FormFeed
+ '\u{000D}' | // CarriageReturn
+ '\u{0085}' | // NextLine
+ '\u{2028}' | // Line Separator
+ '\u{2029}' // ParagraphSeparator
+ )
+}
+
+/// Determine whether a character qualifies as (non-line-break)
+/// whitespace.
+pub fn char_is_whitespace(c: char) -> bool {
+ // TODO: this is a naive binary categorization of whitespace
+ // characters. For display, word wrapping, etc. we'll need a better
+ // categorization based on e.g. breaking vs non-breaking spaces
+ // and whether they're zero-width or not.
+ match c {
+ //'\u{1680}' | // Ogham Space Mark (here for completeness, but usually displayed as a dash, not as whitespace)
+ '\u{0009}' | // Character Tabulation
+ '\u{0020}' | // Space
+ '\u{00A0}' | // No-break Space
+ '\u{180E}' | // Mongolian Vowel Separator
+ '\u{202F}' | // Narrow No-break Space
+ '\u{205F}' | // Medium Mathematical Space
+ '\u{3000}' | // Ideographic Space
+ '\u{FEFF}' // Zero Width No-break Space
+ => true,
+
+ // En Quad, Em Quad, En Space, Em Space, Three-per-em Space,
+ // Four-per-em Space, Six-per-em Space, Figure Space,
+ // Punctuation Space, Thin Space, Hair Space, Zero Width Space.
+ c if ('\u{2000}' ..= '\u{200B}').contains(&c) => true,
+
+ _ => false,
+ }
+}
diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs
index 79a22547..b11faeab 100644
--- a/helix-core/src/lib.rs
+++ b/helix-core/src/lib.rs
@@ -1,5 +1,6 @@
#![allow(unused)]
pub mod auto_pairs;
+pub mod chars;
pub mod comment;
pub mod diagnostic;
pub mod graphemes;