Remove unnecessary helper function

pull/502/head
Wilfred Hughes 2023-04-02 19:28:57 +07:00
parent 2296c9f739
commit 8c004be87b
4 changed files with 18 additions and 49 deletions

@ -5,7 +5,7 @@ use crate::{
display::context::{calculate_after_context, calculate_before_context, opposite_positions},
display::hunks::Hunk,
display::style::{self, apply_colors, apply_line_number_color},
lines::{format_line_num, split_on_newlines, MaxLine},
lines::{format_line_num, MaxLine},
options::DisplayOptions,
parse::syntax::MatchedPos,
summary::FileFormat,
@ -43,14 +43,8 @@ pub fn print(
)
} else {
(
split_on_newlines(lhs_src)
.iter()
.map(|s| format!("{}\n", s))
.collect(),
split_on_newlines(rhs_src)
.iter()
.map(|s| format!("{}\n", s))
.collect(),
lhs_src.lines().map(|s| format!("{}\n", s)).collect(),
rhs_src.lines().map(|s| format!("{}\n", s)).collect(),
)
};

@ -15,7 +15,7 @@ use crate::{
self, apply_colors, apply_line_number_color, color_positions, novel_style, split_and_apply,
BackgroundColor,
},
lines::{codepoint_len, format_line_num, split_on_newlines, LineNumber},
lines::{codepoint_len, format_line_num, LineNumber},
options::{DisplayMode, DisplayOptions},
parse::syntax::{zip_pad_shorter, MatchedPos},
positions::SingleLineSpan,
@ -345,14 +345,8 @@ pub fn print(
)
} else {
(
split_on_newlines(lhs_src)
.iter()
.map(|s| format!("{}\n", s))
.collect(),
split_on_newlines(rhs_src)
.iter()
.map(|s| format!("{}\n", s))
.collect(),
lhs_src.lines().map(|s| format!("{}\n", s)).collect(),
rhs_src.lines().map(|s| format!("{}\n", s)).collect(),
)
};
@ -403,8 +397,8 @@ pub fn print(
let mut prev_lhs_line_num = None;
let mut prev_rhs_line_num = None;
let lhs_lines = split_on_newlines(lhs_src);
let rhs_lines = split_on_newlines(rhs_src);
let lhs_lines = lhs_src.lines().collect::<Vec<_>>();
let rhs_lines = rhs_src.lines().collect::<Vec<_>>();
let matched_lines = all_matched_lines_filled(lhs_mps, rhs_mps, &lhs_lines, &rhs_lines);
let mut matched_lines_to_print = &matched_lines[..];
@ -611,8 +605,10 @@ mod tests {
let source_dims = SourceDimensions::new(
80,
&line_nums,
&split_on_newlines("foo\nbar\n"),
&split_on_newlines("x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n"),
&"foo\nbar\n".lines().collect::<Vec<_>>(),
&"x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n"
.lines()
.collect::<Vec<_>>(),
);
assert_eq!(source_dims.lhs_line_nums_width, 2);
@ -627,8 +623,8 @@ mod tests {
(Some(0.into()), Some(0.into())),
(Some(1.into()), Some(1.into())),
],
&split_on_newlines("foo\nbar\n"),
&split_on_newlines("fox\nbax\n"),
&"foo\nbar\n".lines().collect::<Vec<_>>(),
&"fox\nbax\n".lines().collect::<Vec<_>>(),
);
assert_eq!(
@ -649,8 +645,8 @@ mod tests {
(Some(0.into()), Some(0.into())),
(Some(1.into()), Some(1.into())),
],
&split_on_newlines("foo\nbar\n"),
&split_on_newlines("fox\nbax\n"),
&"foo\nbar\n".lines().collect::<Vec<_>>(),
&"fox\nbax\n".lines().collect::<Vec<_>>(),
);
assert_eq!(

@ -2,7 +2,7 @@
use crate::{
constants::Side,
lines::{byte_len, split_on_newlines, LineNumber},
lines::{byte_len, LineNumber},
options::DisplayOptions,
parse::syntax::{AtomKind, MatchKind, MatchedPos, TokenKind},
positions::SingleLineSpan,
@ -396,7 +396,7 @@ pub fn apply_colors(
positions: &[MatchedPos],
) -> Vec<String> {
let styles = color_positions(side, background, syntax_highlight, file_format, positions);
let lines = split_on_newlines(s);
let lines = s.lines().collect::<Vec<_>>();
style_lines(&lines, &styles)
}

@ -183,12 +183,6 @@ impl<S: AsRef<str>> MaxLine for S {
}
}
/// Split `s` on \n or \r\n. Each line in the vec does not include the
/// trailing newline.
pub fn split_on_newlines(s: &str) -> Vec<&str> {
s.lines().collect()
}
pub fn is_all_whitespace(s: &str) -> bool {
s.chars().all(|c| c.is_whitespace())
}
@ -298,21 +292,6 @@ mod tests {
assert_eq!(codepoint_len("ƒoo"), 3);
}
#[test]
fn test_split_line_single() {
assert_eq!(split_on_newlines("foo"), vec!["foo"]);
}
#[test]
fn test_split_line_with_newline() {
assert_eq!(split_on_newlines("foo\nbar"), vec!["foo", "bar"]);
}
#[test]
fn test_split_line_with_crlf() {
assert_eq!(split_on_newlines("foo\r\nbar"), vec!["foo", "bar"]);
}
#[test]
fn test_is_all_whiteapce() {
assert!(is_all_whitespace(" \n\t"));