@@ -128,6 +128,29 @@ pub fn get_line_ending(line: &RopeSlice) -> Option<LineEnding> {
128128 LineEnding::from_str(g2).or_else(|| LineEnding::from_str(g1))
129129}
130130
131+/// Returns the passed line's line ending, if any.
132+pub fn get_line_ending_of_str(line: &str) -> Option<LineEnding> {
133+ if line.ends_with("\u{000D}\u{000A}") {
134+ Some(LineEnding::Crlf)
135+ } else if line.ends_with("\u{000A}") {
136+ Some(LineEnding::LF)
137+ } else if line.ends_with("\u{000B}") {
138+ Some(LineEnding::VT)
139+ } else if line.ends_with("\u{000C}") {
140+ Some(LineEnding::FF)
141+ } else if line.ends_with("\u{000D}") {
142+ Some(LineEnding::CR)
143+ } else if line.ends_with("\u{0085}") {
144+ Some(LineEnding::Nel)
145+ } else if line.ends_with("\u{2028}") {
146+ Some(LineEnding::LS)
147+ } else if line.ends_with("\u{2029}") {
148+ Some(LineEnding::PS)
149+ } else {
150+ None
151+ }
152+}
153+
131154/// Returns the char index of the end of the given line, not including its line ending.
132155pub fn line_end_char_index(slice: &RopeSlice, line: usize) -> usize {
133156 slice.line_to_char(line + 1)