aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorJan Hrastnik2021-06-17 11:49:50 +0000
committerJan Hrastnik2021-06-17 11:49:50 +0000
commit8bccd6df3054143baf128157d8dcecb10a911956 (patch)
tree86b4cb7c8c369b554e6cde8aac44061bd2bb6afc /helix-core
parent9c3eadb2e4fd297abcc8ceb02b3088ab3b9b1ceb (diff)
applied changes from pr review
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/line_ending.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/helix-core/src/line_ending.rs b/helix-core/src/line_ending.rs
index 4f5708ec..f9d67b57 100644
--- a/helix-core/src/line_ending.rs
+++ b/helix-core/src/line_ending.rs
@@ -13,6 +13,29 @@ pub enum LineEnding {
PS, // U+2029 -- ParagraphSeparator
}
+impl LineEnding {
+ pub fn len(&self) -> usize {
+ match self {
+ Self::Crlf => 2,
+ _ => 1,
+ }
+ }
+
+ pub fn as_str(&self) -> &str {
+ match self {
+ Self::Crlf => "\u{000D}\u{000A}",
+ Self::LF => "\u{000A}",
+ Self::Nel => "\u{0085}",
+ Self::LS => "\u{2028}",
+ Self::CR => "\u{000D}",
+ _ => panic!(
+ "Unexpected line ending: {:?}, expected Crlf, LF, CR, Nel, or LS.",
+ self
+ ),
+ }
+ }
+}
+
pub fn rope_slice_to_line_ending(g: &RopeSlice) -> Option<LineEnding> {
if let Some(text) = g.as_str() {
str_to_line_ending(text)