From 8bccd6df3054143baf128157d8dcecb10a911956 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Thu, 17 Jun 2021 13:49:50 +0200 Subject: applied changes from pr review --- helix-core/src/line_ending.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'helix-core') 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 { if let Some(text) = g.as_str() { str_to_line_ending(text) -- cgit v1.2.3-70-g09d2