aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/line_ending.rs
diff options
context:
space:
mode:
authorNathan Vegdahl2021-06-21 17:29:29 +0000
committerNathan Vegdahl2021-06-21 17:29:29 +0000
commit07e28802f6b61a17e839d05b2a031575f323b9c9 (patch)
treecf28b772ad9b43a125a27dc3018ac09ba1bb2e16 /helix-core/src/line_ending.rs
parent714002048cc9601bf0981435c6d3ad43d1c765e8 (diff)
Add function to get the line ending of a str slice.
This is needed in some places.
Diffstat (limited to 'helix-core/src/line_ending.rs')
-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 3055c96e..19de2231 100644
--- a/helix-core/src/line_ending.rs
+++ b/helix-core/src/line_ending.rs
@@ -128,6 +128,29 @@ pub fn get_line_ending(line: &RopeSlice) -> Option<LineEnding> {
LineEnding::from_str(g2).or_else(|| LineEnding::from_str(g1))
}
+/// Returns the passed line's line ending, if any.
+pub fn get_line_ending_of_str(line: &str) -> Option<LineEnding> {
+ if line.ends_with("\u{000D}\u{000A}") {
+ Some(LineEnding::Crlf)
+ } else if line.ends_with("\u{000A}") {
+ Some(LineEnding::LF)
+ } else if line.ends_with("\u{000B}") {
+ Some(LineEnding::VT)
+ } else if line.ends_with("\u{000C}") {
+ Some(LineEnding::FF)
+ } else if line.ends_with("\u{000D}") {
+ Some(LineEnding::CR)
+ } else if line.ends_with("\u{0085}") {
+ Some(LineEnding::Nel)
+ } else if line.ends_with("\u{2028}") {
+ Some(LineEnding::LS)
+ } else if line.ends_with("\u{2029}") {
+ Some(LineEnding::PS)
+ } else {
+ None
+ }
+}
+
/// Returns the char index of the end of the given line, not including its line ending.
pub fn line_end_char_index(slice: &RopeSlice, line: usize) -> usize {
slice.line_to_char(line + 1)