csplit - rustfmt

This commit is contained in:
Sylvestre Ledru 2020-12-28 14:37:33 +01:00
parent 3a1eb1e05f
commit 7955d346a8
4 changed files with 32 additions and 31 deletions

View file

@ -6,24 +6,20 @@ extern crate failure;
extern crate uucore;
extern crate getopts;
extern crate regex;
use std::{fs::{File, remove_file}, io::{BufRead, BufWriter, Write}};
use std::io::{self, BufReader};
use getopts::Matches;
use regex::Regex;
/*
mod split_name;
mod patterns;
*/
mod splitname;
mod patterns;
use std::io::{self, BufReader};
use std::{
fs::{remove_file, File},
io::{BufRead, BufWriter, Write},
};
mod csplit_error;
mod patterns;
mod splitname;
use crate::splitname::SplitName;
use crate::csplit_error::CsplitError;
//mod split_name;
//mod csplit;
use crate::splitname::SplitName;
static SYNTAX: &str = "[OPTION]... FILE PATTERN...";
static SUMMARY: &str = "split a file into sections determined by context lines";
@ -325,7 +321,8 @@ impl<'a> SplitWriter<'a> {
ret = Ok(());
break;
} else if ln + 1 == n {
if !self.options.suppress_matched && input_iter.add_line_to_buffer(ln, l).is_some() {
if !self.options.suppress_matched && input_iter.add_line_to_buffer(ln, l).is_some()
{
panic!("the buffer is big enough to contain 1 line");
}
ret = Ok(());

View file

@ -15,7 +15,10 @@ pub enum CsplitError {
MatchNotFoundOnRepetition(String, usize),
#[fail(display = "line number must be greater than zero")]
LineNumberIsZero,
#[fail(display = "line number '{}' is smaller than preceding line number, {}", _0, _1)]
#[fail(
display = "line number '{}' is smaller than preceding line number, {}",
_0, _1
)]
LineNumberSmallerThanPrevious(usize, usize),
#[fail(display = "invalid pattern: {}", _0)]
InvalidPattern(String),

View file

@ -1,5 +1,5 @@
use regex::Regex;
use crate::csplit_error::CsplitError;
use regex::Regex;
/// The definition of a pattern to match on a line.
#[derive(Debug)]
@ -221,7 +221,8 @@ mod tests {
"{4}",
"/test4.*end$/+3",
"/test5.*end$/-3",
].into_iter()
]
.into_iter()
.map(|v| v.to_string())
.collect();
let patterns = get_patterns(input.as_slice()).unwrap();
@ -273,7 +274,8 @@ mod tests {
"{4}",
"%test4.*end$%+3",
"%test5.*end$%-3",
].into_iter()
]
.into_iter()
.map(|v| v.to_string())
.collect();
let patterns = get_patterns(input.as_slice()).unwrap();

View file

@ -44,9 +44,9 @@ impl SplitName {
format!("{}{:0width$}", prefix, n, width = n_digits)
}),
Some(custom) => {
let spec = Regex::new(
r"(?P<ALL>%(?P<FLAG>[0#-])(?P<WIDTH>\d+)?(?P<TYPE>[diuoxX]))",
).unwrap();
let spec =
Regex::new(r"(?P<ALL>%(?P<FLAG>[0#-])(?P<WIDTH>\d+)?(?P<TYPE>[diuoxX]))")
.unwrap();
let mut captures_iter = spec.captures_iter(&custom);
let custom_fn: Box<dyn Fn(usize) -> String> = match captures_iter.next() {
Some(captures) => {
@ -63,7 +63,6 @@ impl SplitName {
/*
* zero padding
*/
// decimal
("0", "d") | ("0", "i") | ("0", "u") => {
Box::new(move |n: usize| -> String {
@ -114,7 +113,6 @@ impl SplitName {
/*
* Alternate form
*/
// octal
("#", "o") => Box::new(move |n: usize| -> String {
format!(
@ -152,7 +150,6 @@ impl SplitName {
/*
* Left adjusted
*/
// decimal
("-", "d") | ("-", "i") | ("-", "u") => {
Box::new(move |n: usize| -> String {
@ -287,7 +284,8 @@ mod tests {
Some(String::from("pre-")),
Some(String::from("cst-%03d-post")),
None,
).unwrap();
)
.unwrap();
assert_eq!(split_name.get(2), "pre-cst-002-post");
}
@ -297,7 +295,8 @@ mod tests {
None,
Some(String::from("cst-%03d-")),
Some(String::from("42")),
).unwrap();
)
.unwrap();
assert_eq!(split_name.get(2), "xxcst-002-");
}