From ea4d3977b75d66146fd80a66d2121123d653102e Mon Sep 17 00:00:00 2001 From: sylvestre Date: Fri, 21 Jul 2023 02:37:35 +0000 Subject: [PATCH] deploy: f0e8d44e6e64ee3354f95864c0a25b74cf1c1151 --- dev/src/uu_nl/nl.rs.html | 106 ++++++------------ dev/uu_nl/fn.uu_app.html | 2 +- dev/uu_nl/fn.uumain.html | 2 +- dev/uu_nl/index.html | 2 +- .../options/constant.BODY_NUMBERING.html | 2 +- dev/uu_nl/options/constant.FILE.html | 2 +- .../options/constant.FOOTER_NUMBERING.html | 2 +- .../options/constant.HEADER_NUMBERING.html | 2 +- dev/uu_nl/options/constant.HELP.html | 2 +- .../options/constant.JOIN_BLANK_LINES.html | 2 +- .../options/constant.LINE_INCREMENT.html | 2 +- dev/uu_nl/options/constant.NO_RENUMBER.html | 2 +- dev/uu_nl/options/constant.NUMBER_FORMAT.html | 2 +- .../options/constant.NUMBER_SEPARATOR.html | 2 +- dev/uu_nl/options/constant.NUMBER_WIDTH.html | 2 +- .../options/constant.SECTION_DELIMITER.html | 2 +- .../constant.STARTING_LINE_NUMBER.html | 2 +- dev/uu_nl/options/index.html | 2 +- dev/uu_nl/struct.Settings.html | 2 +- 19 files changed, 54 insertions(+), 88 deletions(-) diff --git a/dev/src/uu_nl/nl.rs.html b/dev/src/uu_nl/nl.rs.html index 5356c7607..7ed5cde8b 100644 --- a/dev/src/uu_nl/nl.rs.html +++ b/dev/src/uu_nl/nl.rs.html @@ -433,23 +433,6 @@ 433 434 435 -436 -437 -438 -439 -440 -441 -442 -443 -444 -445 -446 -447 -448 -449 -450 -451 -452
//  * This file is part of the uutils coreutils package.
 //  *
 //  * (c) Tobias Bohumir Schottdorf <tobias.schottdorf@gmail.com>
@@ -461,7 +444,6 @@
 use clap::{crate_version, Arg, ArgAction, Command};
 use std::fs::File;
 use std::io::{stdin, BufRead, BufReader, Read};
-use std::iter::repeat;
 use std::path::Path;
 use uucore::error::{FromIo, UResult, USimpleError};
 use uucore::{format_usage, help_about, help_section, help_usage};
@@ -547,6 +529,19 @@
     }
 }
 
+impl NumberFormat {
+    // Turns a line number into a `String` with at least `min_width` chars,
+    // formatted according to the `NumberFormat`s variant.
+    fn format(&self, number: i64, min_width: usize) -> String {
+        match self {
+            Self::Left => format!("{number:<min_width$}"),
+            Self::Right => format!("{number:>min_width$}"),
+            Self::RightZero if number < 0 => format!("-{0:0>1$}", number.abs(), min_width - 1),
+            Self::RightZero => format!("{number:0>min_width$}"),
+        }
+    }
+}
+
 pub mod options {
     pub const HELP: &str = "help";
     pub const FILE: &str = "file";
@@ -715,13 +710,7 @@
 fn nl<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UResult<()> {
     let regexp: regex::Regex = regex::Regex::new(r".?").unwrap();
     let mut line_no = settings.starting_line_number;
-    let mut line_no_width = line_no.len();
-    let line_no_width_initial = line_no_width;
     let mut empty_line_count: u64 = 0;
-    let fill_char = match settings.number_format {
-        NumberFormat::RightZero => '0',
-        _ => ' ',
-    };
     // Initially, we use the body's line counting settings
     let mut regex_filter = match settings.body_numbering {
         NumberingStyle::NumberForRegularExpression(ref re) => re,
@@ -774,10 +763,9 @@
             match *match matched_groups {
                 3 => {
                     // This is a header, so we may need to reset the
-                    // line number and the line width
+                    // line number
                     if settings.renumber {
                         line_no = settings.starting_line_number;
-                        line_no_width = line_no_width_initial;
                     }
                     &settings.header_numbering
                 }
@@ -827,26 +815,17 @@
         // way, start counting empties from zero once more.
         empty_line_count = 0;
         // A line number is to be printed.
-        let w = if settings.number_width > line_no_width {
-            settings.number_width - line_no_width
-        } else {
-            0
-        };
-        let fill: String = repeat(fill_char).take(w).collect();
-        match settings.number_format {
-            NumberFormat::Left => println!(
-                "{1}{0}{2}{3}",
-                fill, line_no, settings.number_separator, line
-            ),
-            _ => println!(
-                "{0}{1}{2}{3}",
-                fill, line_no, settings.number_separator, line
-            ),
-        }
-        // Now update the variables for the (potential) next
+        println!(
+            "{}{}{}",
+            settings
+                .number_format
+                .format(line_no, settings.number_width),
+            settings.number_separator,
+            line
+        );
+        // Now update the line number for the (potential) next
         // line.
         line_no += settings.line_increment;
-        line_no_width = line_no.len();
     }
     Ok(())
 }
@@ -867,39 +846,26 @@
     true
 }
 
-trait Length {
-    fn len(&self) -> usize;
-}
-
-impl Length for i64 {
-    // Returns the length in `char`s.
-    fn len(&self) -> usize {
-        if *self == 0 {
-            return 1;
-        };
-
-        let sign_len = if *self < 0 { 1 } else { 0 };
-        (0..).take_while(|i| 10i64.pow(*i) <= self.abs()).count() + sign_len
-    }
-}
-
 #[cfg(test)]
 mod test {
     use super::*;
 
     #[test]
-    fn test_len() {
-        assert_eq!((-1).len(), 2);
-        assert_eq!((-10).len(), 3);
-        assert_eq!((-100).len(), 4);
-        assert_eq!((-1000).len(), 5);
+    fn test_format() {
+        assert_eq!(NumberFormat::Left.format(12, 1), "12");
+        assert_eq!(NumberFormat::Left.format(-12, 1), "-12");
+        assert_eq!(NumberFormat::Left.format(12, 4), "12  ");
+        assert_eq!(NumberFormat::Left.format(-12, 4), "-12 ");
 
-        assert_eq!(0.len(), 1);
+        assert_eq!(NumberFormat::Right.format(12, 1), "12");
+        assert_eq!(NumberFormat::Right.format(-12, 1), "-12");
+        assert_eq!(NumberFormat::Right.format(12, 4), "  12");
+        assert_eq!(NumberFormat::Right.format(-12, 4), " -12");
 
-        assert_eq!(1.len(), 1);
-        assert_eq!(10.len(), 2);
-        assert_eq!(100.len(), 3);
-        assert_eq!(1000.len(), 4);
+        assert_eq!(NumberFormat::RightZero.format(12, 1), "12");
+        assert_eq!(NumberFormat::RightZero.format(-12, 1), "-12");
+        assert_eq!(NumberFormat::RightZero.format(12, 4), "0012");
+        assert_eq!(NumberFormat::RightZero.format(-12, 4), "-012");
     }
 }
 
\ No newline at end of file diff --git a/dev/uu_nl/fn.uu_app.html b/dev/uu_nl/fn.uu_app.html index d484ab848..f81779f84 100644 --- a/dev/uu_nl/fn.uu_app.html +++ b/dev/uu_nl/fn.uu_app.html @@ -1 +1 @@ -uu_app in uu_nl - Rust

Function uu_nl::uu_app

source ·
pub fn uu_app() -> Command
\ No newline at end of file +uu_app in uu_nl - Rust

Function uu_nl::uu_app

source ·
pub fn uu_app() -> Command
\ No newline at end of file diff --git a/dev/uu_nl/fn.uumain.html b/dev/uu_nl/fn.uumain.html index 15bc480ca..1b7213918 100644 --- a/dev/uu_nl/fn.uumain.html +++ b/dev/uu_nl/fn.uumain.html @@ -1 +1 @@ -uumain in uu_nl - Rust

Function uu_nl::uumain

source ·
pub fn uumain(args: impl Args) -> i32
\ No newline at end of file +uumain in uu_nl - Rust

Function uu_nl::uumain

source ·
pub fn uumain(args: impl Args) -> i32
\ No newline at end of file diff --git a/dev/uu_nl/index.html b/dev/uu_nl/index.html index 700c4e30f..1b51122d1 100644 --- a/dev/uu_nl/index.html +++ b/dev/uu_nl/index.html @@ -1 +1 @@ -uu_nl - Rust
\ No newline at end of file +uu_nl - Rust
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.BODY_NUMBERING.html b/dev/uu_nl/options/constant.BODY_NUMBERING.html index ea2d76d7c..6bcbd9b26 100644 --- a/dev/uu_nl/options/constant.BODY_NUMBERING.html +++ b/dev/uu_nl/options/constant.BODY_NUMBERING.html @@ -1 +1 @@ -BODY_NUMBERING in uu_nl::options - Rust

Constant uu_nl::options::BODY_NUMBERING

source ·
pub const BODY_NUMBERING: &str = "body-numbering";
\ No newline at end of file +BODY_NUMBERING in uu_nl::options - Rust

Constant uu_nl::options::BODY_NUMBERING

source ·
pub const BODY_NUMBERING: &str = "body-numbering";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.FILE.html b/dev/uu_nl/options/constant.FILE.html index 5595d4ee6..b9b96f321 100644 --- a/dev/uu_nl/options/constant.FILE.html +++ b/dev/uu_nl/options/constant.FILE.html @@ -1 +1 @@ -FILE in uu_nl::options - Rust

Constant uu_nl::options::FILE

source ·
pub const FILE: &str = "file";
\ No newline at end of file +FILE in uu_nl::options - Rust

Constant uu_nl::options::FILE

source ·
pub const FILE: &str = "file";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.FOOTER_NUMBERING.html b/dev/uu_nl/options/constant.FOOTER_NUMBERING.html index 8d5e64131..0509384b5 100644 --- a/dev/uu_nl/options/constant.FOOTER_NUMBERING.html +++ b/dev/uu_nl/options/constant.FOOTER_NUMBERING.html @@ -1 +1 @@ -FOOTER_NUMBERING in uu_nl::options - Rust
pub const FOOTER_NUMBERING: &str = "footer-numbering";
\ No newline at end of file +FOOTER_NUMBERING in uu_nl::options - Rust
pub const FOOTER_NUMBERING: &str = "footer-numbering";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.HEADER_NUMBERING.html b/dev/uu_nl/options/constant.HEADER_NUMBERING.html index ff9f04923..fd42e852f 100644 --- a/dev/uu_nl/options/constant.HEADER_NUMBERING.html +++ b/dev/uu_nl/options/constant.HEADER_NUMBERING.html @@ -1 +1 @@ -HEADER_NUMBERING in uu_nl::options - Rust
pub const HEADER_NUMBERING: &str = "header-numbering";
\ No newline at end of file +HEADER_NUMBERING in uu_nl::options - Rust
pub const HEADER_NUMBERING: &str = "header-numbering";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.HELP.html b/dev/uu_nl/options/constant.HELP.html index 26c821543..cdd9ed11f 100644 --- a/dev/uu_nl/options/constant.HELP.html +++ b/dev/uu_nl/options/constant.HELP.html @@ -1 +1 @@ -HELP in uu_nl::options - Rust

Constant uu_nl::options::HELP

source ·
pub const HELP: &str = "help";
\ No newline at end of file +HELP in uu_nl::options - Rust

Constant uu_nl::options::HELP

source ·
pub const HELP: &str = "help";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.JOIN_BLANK_LINES.html b/dev/uu_nl/options/constant.JOIN_BLANK_LINES.html index d32f4537a..6da910ed2 100644 --- a/dev/uu_nl/options/constant.JOIN_BLANK_LINES.html +++ b/dev/uu_nl/options/constant.JOIN_BLANK_LINES.html @@ -1 +1 @@ -JOIN_BLANK_LINES in uu_nl::options - Rust
pub const JOIN_BLANK_LINES: &str = "join-blank-lines";
\ No newline at end of file +JOIN_BLANK_LINES in uu_nl::options - Rust
pub const JOIN_BLANK_LINES: &str = "join-blank-lines";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.LINE_INCREMENT.html b/dev/uu_nl/options/constant.LINE_INCREMENT.html index 019443369..f1ef4528e 100644 --- a/dev/uu_nl/options/constant.LINE_INCREMENT.html +++ b/dev/uu_nl/options/constant.LINE_INCREMENT.html @@ -1 +1 @@ -LINE_INCREMENT in uu_nl::options - Rust

Constant uu_nl::options::LINE_INCREMENT

source ·
pub const LINE_INCREMENT: &str = "line-increment";
\ No newline at end of file +LINE_INCREMENT in uu_nl::options - Rust

Constant uu_nl::options::LINE_INCREMENT

source ·
pub const LINE_INCREMENT: &str = "line-increment";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.NO_RENUMBER.html b/dev/uu_nl/options/constant.NO_RENUMBER.html index 2af99a37e..f3ea2d3ca 100644 --- a/dev/uu_nl/options/constant.NO_RENUMBER.html +++ b/dev/uu_nl/options/constant.NO_RENUMBER.html @@ -1 +1 @@ -NO_RENUMBER in uu_nl::options - Rust

Constant uu_nl::options::NO_RENUMBER

source ·
pub const NO_RENUMBER: &str = "no-renumber";
\ No newline at end of file +NO_RENUMBER in uu_nl::options - Rust

Constant uu_nl::options::NO_RENUMBER

source ·
pub const NO_RENUMBER: &str = "no-renumber";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.NUMBER_FORMAT.html b/dev/uu_nl/options/constant.NUMBER_FORMAT.html index f1d196002..2816789aa 100644 --- a/dev/uu_nl/options/constant.NUMBER_FORMAT.html +++ b/dev/uu_nl/options/constant.NUMBER_FORMAT.html @@ -1 +1 @@ -NUMBER_FORMAT in uu_nl::options - Rust

Constant uu_nl::options::NUMBER_FORMAT

source ·
pub const NUMBER_FORMAT: &str = "number-format";
\ No newline at end of file +NUMBER_FORMAT in uu_nl::options - Rust

Constant uu_nl::options::NUMBER_FORMAT

source ·
pub const NUMBER_FORMAT: &str = "number-format";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.NUMBER_SEPARATOR.html b/dev/uu_nl/options/constant.NUMBER_SEPARATOR.html index 52af83dd6..5ae66fe38 100644 --- a/dev/uu_nl/options/constant.NUMBER_SEPARATOR.html +++ b/dev/uu_nl/options/constant.NUMBER_SEPARATOR.html @@ -1 +1 @@ -NUMBER_SEPARATOR in uu_nl::options - Rust
pub const NUMBER_SEPARATOR: &str = "number-separator";
\ No newline at end of file +NUMBER_SEPARATOR in uu_nl::options - Rust
pub const NUMBER_SEPARATOR: &str = "number-separator";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.NUMBER_WIDTH.html b/dev/uu_nl/options/constant.NUMBER_WIDTH.html index 6023da42a..121a36bf5 100644 --- a/dev/uu_nl/options/constant.NUMBER_WIDTH.html +++ b/dev/uu_nl/options/constant.NUMBER_WIDTH.html @@ -1 +1 @@ -NUMBER_WIDTH in uu_nl::options - Rust

Constant uu_nl::options::NUMBER_WIDTH

source ·
pub const NUMBER_WIDTH: &str = "number-width";
\ No newline at end of file +NUMBER_WIDTH in uu_nl::options - Rust

Constant uu_nl::options::NUMBER_WIDTH

source ·
pub const NUMBER_WIDTH: &str = "number-width";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.SECTION_DELIMITER.html b/dev/uu_nl/options/constant.SECTION_DELIMITER.html index c329bee12..4cc736c98 100644 --- a/dev/uu_nl/options/constant.SECTION_DELIMITER.html +++ b/dev/uu_nl/options/constant.SECTION_DELIMITER.html @@ -1 +1 @@ -SECTION_DELIMITER in uu_nl::options - Rust
pub const SECTION_DELIMITER: &str = "section-delimiter";
\ No newline at end of file +SECTION_DELIMITER in uu_nl::options - Rust
pub const SECTION_DELIMITER: &str = "section-delimiter";
\ No newline at end of file diff --git a/dev/uu_nl/options/constant.STARTING_LINE_NUMBER.html b/dev/uu_nl/options/constant.STARTING_LINE_NUMBER.html index b6798afb8..f330439dc 100644 --- a/dev/uu_nl/options/constant.STARTING_LINE_NUMBER.html +++ b/dev/uu_nl/options/constant.STARTING_LINE_NUMBER.html @@ -1 +1 @@ -STARTING_LINE_NUMBER in uu_nl::options - Rust
pub const STARTING_LINE_NUMBER: &str = "starting-line-number";
\ No newline at end of file +STARTING_LINE_NUMBER in uu_nl::options - Rust
pub const STARTING_LINE_NUMBER: &str = "starting-line-number";
\ No newline at end of file diff --git a/dev/uu_nl/options/index.html b/dev/uu_nl/options/index.html index d270ee37b..caebad413 100644 --- a/dev/uu_nl/options/index.html +++ b/dev/uu_nl/options/index.html @@ -1 +1 @@ -uu_nl::options - Rust
\ No newline at end of file +uu_nl::options - Rust
\ No newline at end of file diff --git a/dev/uu_nl/struct.Settings.html b/dev/uu_nl/struct.Settings.html index 025cdd51e..7810073bd 100644 --- a/dev/uu_nl/struct.Settings.html +++ b/dev/uu_nl/struct.Settings.html @@ -1,4 +1,4 @@ -Settings in uu_nl - Rust

Struct uu_nl::Settings

source ·
pub struct Settings { /* private fields */ }

Trait Implementations§

source§

impl Default for Settings

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere +Settings in uu_nl - Rust

Struct uu_nl::Settings

source ·
pub struct Settings { /* private fields */ }

Trait Implementations§

source§

impl Default for Settings

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.