diff options
author | Jan Hrastnik | 2021-06-20 00:22:10 +0000 |
---|---|---|
committer | Jan Hrastnik | 2021-06-20 00:22:10 +0000 |
commit | 8634e04a31f8f761b3d0505528295d31d63c7918 (patch) | |
tree | 07bf80760d41f2f13c125bc38e15b0dd389d64f1 /helix-core/src/line_ending.rs | |
parent | 701eb0dd6800e75116f36e503787dd0f50df709e (diff) |
added the line_end helper function
Diffstat (limited to 'helix-core/src/line_ending.rs')
-rw-r--r-- | helix-core/src/line_ending.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/helix-core/src/line_ending.rs b/helix-core/src/line_ending.rs index 33f8d078..f6118493 100644 --- a/helix-core/src/line_ending.rs +++ b/helix-core/src/line_ending.rs @@ -111,6 +111,12 @@ pub fn get_line_ending(line: &RopeSlice) -> Option<LineEnding> { str_to_line_ending(g2).or_else(|| str_to_line_ending(g1)) } +pub fn line_end(slice: &RopeSlice, line: usize) -> usize { + slice.line_to_char(line + 1).saturating_sub(get_line_ending(&slice.line(line)) + .map(|le| le.len_chars()) + .unwrap_or(0)) +} + #[cfg(target_os = "windows")] pub const DEFAULT_LINE_ENDING: LineEnding = LineEnding::Crlf; #[cfg(not(target_os = "windows"))] |