mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 10:18:11 +00:00
csplit - rustfmt
This commit is contained in:
parent
3a1eb1e05f
commit
7955d346a8
4 changed files with 32 additions and 31 deletions
|
@ -6,24 +6,20 @@ extern crate failure;
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
use std::{fs::{File, remove_file}, io::{BufRead, BufWriter, Write}};
|
|
||||||
use std::io::{self, BufReader};
|
|
||||||
use getopts::Matches;
|
use getopts::Matches;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
/*
|
use std::io::{self, BufReader};
|
||||||
mod split_name;
|
use std::{
|
||||||
mod patterns;
|
fs::{remove_file, File},
|
||||||
*/
|
io::{BufRead, BufWriter, Write},
|
||||||
mod splitname;
|
};
|
||||||
mod patterns;
|
|
||||||
mod csplit_error;
|
mod csplit_error;
|
||||||
|
mod patterns;
|
||||||
|
mod splitname;
|
||||||
|
|
||||||
use crate::splitname::SplitName;
|
|
||||||
use crate::csplit_error::CsplitError;
|
use crate::csplit_error::CsplitError;
|
||||||
//mod split_name;
|
use crate::splitname::SplitName;
|
||||||
|
|
||||||
|
|
||||||
//mod csplit;
|
|
||||||
|
|
||||||
static SYNTAX: &str = "[OPTION]... FILE PATTERN...";
|
static SYNTAX: &str = "[OPTION]... FILE PATTERN...";
|
||||||
static SUMMARY: &str = "split a file into sections determined by context lines";
|
static SUMMARY: &str = "split a file into sections determined by context lines";
|
||||||
|
@ -325,7 +321,8 @@ impl<'a> SplitWriter<'a> {
|
||||||
ret = Ok(());
|
ret = Ok(());
|
||||||
break;
|
break;
|
||||||
} else if ln + 1 == n {
|
} 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");
|
panic!("the buffer is big enough to contain 1 line");
|
||||||
}
|
}
|
||||||
ret = Ok(());
|
ret = Ok(());
|
||||||
|
|
|
@ -15,7 +15,10 @@ pub enum CsplitError {
|
||||||
MatchNotFoundOnRepetition(String, usize),
|
MatchNotFoundOnRepetition(String, usize),
|
||||||
#[fail(display = "line number must be greater than zero")]
|
#[fail(display = "line number must be greater than zero")]
|
||||||
LineNumberIsZero,
|
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),
|
LineNumberSmallerThanPrevious(usize, usize),
|
||||||
#[fail(display = "invalid pattern: {}", _0)]
|
#[fail(display = "invalid pattern: {}", _0)]
|
||||||
InvalidPattern(String),
|
InvalidPattern(String),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use regex::Regex;
|
|
||||||
use crate::csplit_error::CsplitError;
|
use crate::csplit_error::CsplitError;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
/// The definition of a pattern to match on a line.
|
/// The definition of a pattern to match on a line.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -221,7 +221,8 @@ mod tests {
|
||||||
"{4}",
|
"{4}",
|
||||||
"/test4.*end$/+3",
|
"/test4.*end$/+3",
|
||||||
"/test5.*end$/-3",
|
"/test5.*end$/-3",
|
||||||
].into_iter()
|
]
|
||||||
|
.into_iter()
|
||||||
.map(|v| v.to_string())
|
.map(|v| v.to_string())
|
||||||
.collect();
|
.collect();
|
||||||
let patterns = get_patterns(input.as_slice()).unwrap();
|
let patterns = get_patterns(input.as_slice()).unwrap();
|
||||||
|
@ -273,7 +274,8 @@ mod tests {
|
||||||
"{4}",
|
"{4}",
|
||||||
"%test4.*end$%+3",
|
"%test4.*end$%+3",
|
||||||
"%test5.*end$%-3",
|
"%test5.*end$%-3",
|
||||||
].into_iter()
|
]
|
||||||
|
.into_iter()
|
||||||
.map(|v| v.to_string())
|
.map(|v| v.to_string())
|
||||||
.collect();
|
.collect();
|
||||||
let patterns = get_patterns(input.as_slice()).unwrap();
|
let patterns = get_patterns(input.as_slice()).unwrap();
|
||||||
|
|
|
@ -44,9 +44,9 @@ impl SplitName {
|
||||||
format!("{}{:0width$}", prefix, n, width = n_digits)
|
format!("{}{:0width$}", prefix, n, width = n_digits)
|
||||||
}),
|
}),
|
||||||
Some(custom) => {
|
Some(custom) => {
|
||||||
let spec = Regex::new(
|
let spec =
|
||||||
r"(?P<ALL>%(?P<FLAG>[0#-])(?P<WIDTH>\d+)?(?P<TYPE>[diuoxX]))",
|
Regex::new(r"(?P<ALL>%(?P<FLAG>[0#-])(?P<WIDTH>\d+)?(?P<TYPE>[diuoxX]))")
|
||||||
).unwrap();
|
.unwrap();
|
||||||
let mut captures_iter = spec.captures_iter(&custom);
|
let mut captures_iter = spec.captures_iter(&custom);
|
||||||
let custom_fn: Box<dyn Fn(usize) -> String> = match captures_iter.next() {
|
let custom_fn: Box<dyn Fn(usize) -> String> = match captures_iter.next() {
|
||||||
Some(captures) => {
|
Some(captures) => {
|
||||||
|
@ -63,7 +63,6 @@ impl SplitName {
|
||||||
/*
|
/*
|
||||||
* zero padding
|
* zero padding
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// decimal
|
// decimal
|
||||||
("0", "d") | ("0", "i") | ("0", "u") => {
|
("0", "d") | ("0", "i") | ("0", "u") => {
|
||||||
Box::new(move |n: usize| -> String {
|
Box::new(move |n: usize| -> String {
|
||||||
|
@ -114,7 +113,6 @@ impl SplitName {
|
||||||
/*
|
/*
|
||||||
* Alternate form
|
* Alternate form
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// octal
|
// octal
|
||||||
("#", "o") => Box::new(move |n: usize| -> String {
|
("#", "o") => Box::new(move |n: usize| -> String {
|
||||||
format!(
|
format!(
|
||||||
|
@ -152,7 +150,6 @@ impl SplitName {
|
||||||
/*
|
/*
|
||||||
* Left adjusted
|
* Left adjusted
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// decimal
|
// decimal
|
||||||
("-", "d") | ("-", "i") | ("-", "u") => {
|
("-", "d") | ("-", "i") | ("-", "u") => {
|
||||||
Box::new(move |n: usize| -> String {
|
Box::new(move |n: usize| -> String {
|
||||||
|
@ -287,7 +284,8 @@ mod tests {
|
||||||
Some(String::from("pre-")),
|
Some(String::from("pre-")),
|
||||||
Some(String::from("cst-%03d-post")),
|
Some(String::from("cst-%03d-post")),
|
||||||
None,
|
None,
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
assert_eq!(split_name.get(2), "pre-cst-002-post");
|
assert_eq!(split_name.get(2), "pre-cst-002-post");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +295,8 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
Some(String::from("cst-%03d-")),
|
Some(String::from("cst-%03d-")),
|
||||||
Some(String::from("42")),
|
Some(String::from("42")),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
assert_eq!(split_name.get(2), "xxcst-002-");
|
assert_eq!(split_name.get(2), "xxcst-002-");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue