summaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
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)