@@ -128,6 +128,29 @@ pub fn get_line_ending(line: &RopeSlice) -> Option<LineEnding> {
128 LineEnding::from_str(g2).or_else(|| LineEnding::from_str(g1))
128 LineEnding::from_str(g2).or_else(|| LineEnding::from_str(g1))
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)
131/// Returns the char index of the end of the given line, not including its line ending.
154/// Returns the char index of the end of the given line, not including its line ending.
132pub fn line_end_char_index(slice: &RopeSlice, line: usize) -> usize {
155pub fn line_end_char_index(slice: &RopeSlice, line: usize) -> usize {
133 slice.line_to_char(line + 1)
156 slice.line_to_char(line + 1)