mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
seq: combine first, inc, last parameters into type
Combine the `first`, `increment`, and `last` parameters of the `print_seq()` and `print_seq_integers()` functions into a `RangeF64` or `RangeInt` type, respectively.
This commit is contained in:
parent
afb460f4ca
commit
1df9a1691c
1 changed files with 16 additions and 13 deletions
|
@ -85,6 +85,16 @@ impl FromStr for Number {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A range of integers.
|
||||||
|
///
|
||||||
|
/// The elements are (first, increment, last).
|
||||||
|
type RangeInt = (BigInt, BigInt, BigInt);
|
||||||
|
|
||||||
|
/// A range of f64.
|
||||||
|
///
|
||||||
|
/// The elements are (first, increment, last).
|
||||||
|
type RangeF64 = (f64, f64, f64);
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let usage = usage();
|
let usage = usage();
|
||||||
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
|
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
|
||||||
|
@ -139,9 +149,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
match (first, last, increment) {
|
match (first, last, increment) {
|
||||||
(Number::BigInt(first), Number::BigInt(last), Number::BigInt(increment)) => {
|
(Number::BigInt(first), Number::BigInt(last), Number::BigInt(increment)) => {
|
||||||
print_seq_integers(
|
print_seq_integers(
|
||||||
first,
|
(first, increment, last),
|
||||||
increment,
|
|
||||||
last,
|
|
||||||
options.separator,
|
options.separator,
|
||||||
options.terminator,
|
options.terminator,
|
||||||
options.widths,
|
options.widths,
|
||||||
|
@ -149,9 +157,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
(first, last, increment) => print_seq(
|
(first, last, increment) => print_seq(
|
||||||
first.into_f64(),
|
(first.into_f64(), increment.into_f64(), last.into_f64()),
|
||||||
increment.into_f64(),
|
|
||||||
last.into_f64(),
|
|
||||||
largest_dec,
|
largest_dec,
|
||||||
options.separator,
|
options.separator,
|
||||||
options.terminator,
|
options.terminator,
|
||||||
|
@ -208,17 +214,15 @@ fn done_printing<T: Num + PartialOrd>(next: &T, increment: &T, last: &T) -> bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Floating point based code path
|
/// Floating point based code path
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
fn print_seq(
|
fn print_seq(
|
||||||
first: f64,
|
range: RangeF64,
|
||||||
increment: f64,
|
|
||||||
last: f64,
|
|
||||||
largest_dec: usize,
|
largest_dec: usize,
|
||||||
separator: String,
|
separator: String,
|
||||||
terminator: String,
|
terminator: String,
|
||||||
pad: bool,
|
pad: bool,
|
||||||
padding: usize,
|
padding: usize,
|
||||||
) {
|
) {
|
||||||
|
let (first, increment, last) = range;
|
||||||
let mut i = 0isize;
|
let mut i = 0isize;
|
||||||
let mut value = first + i as f64 * increment;
|
let mut value = first + i as f64 * increment;
|
||||||
while !done_printing(&value, &increment, &last) {
|
while !done_printing(&value, &increment, &last) {
|
||||||
|
@ -245,14 +249,13 @@ fn print_seq(
|
||||||
|
|
||||||
/// BigInt based code path
|
/// BigInt based code path
|
||||||
fn print_seq_integers(
|
fn print_seq_integers(
|
||||||
first: BigInt,
|
range: RangeInt,
|
||||||
increment: BigInt,
|
|
||||||
last: BigInt,
|
|
||||||
separator: String,
|
separator: String,
|
||||||
terminator: String,
|
terminator: String,
|
||||||
pad: bool,
|
pad: bool,
|
||||||
padding: usize,
|
padding: usize,
|
||||||
) {
|
) {
|
||||||
|
let (first, increment, last) = range;
|
||||||
let mut value = first;
|
let mut value = first;
|
||||||
let mut is_first_iteration = true;
|
let mut is_first_iteration = true;
|
||||||
while !done_printing(&value, &increment, &last) {
|
while !done_printing(&value, &increment, &last) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue