diff --git a/src/uu_seq/seq.rs.html b/src/uu_seq/seq.rs.html index 35bc44d54..e2ac7d381 100644 --- a/src/uu_seq/seq.rs.html +++ b/src/uu_seq/seq.rs.html @@ -316,6 +316,60 @@ 314 315 316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370
 // TODO: Make -w flag work with decimals
 // TODO: Support -f flag
@@ -380,6 +434,38 @@
             Number::F64(n) => n,
         }
     }
+
+    /// Number of characters needed to print the integral part of the number.
+    ///
+    /// The number of characters includes one character to represent the
+    /// minus sign ("-") if this number is negative.
+    ///
+    /// # Examples
+    ///
+    /// ```rust,ignore
+    /// use num_bigint::{BigInt, Sign};
+    ///
+    /// assert_eq!(
+    ///     Number::BigInt(BigInt::new(Sign::Plus, vec![123])).num_digits(),
+    ///     3
+    /// );
+    /// assert_eq!(
+    ///     Number::BigInt(BigInt::new(Sign::Minus, vec![123])).num_digits(),
+    ///     4
+    /// );
+    /// assert_eq!(Number::F64(123.45).num_digits(), 3);
+    /// assert_eq!(Number::MinusZero.num_digits(), 2);
+    /// ```
+    fn num_digits(&self) -> usize {
+        match self {
+            Number::MinusZero => 2,
+            Number::BigInt(n) => n.to_string().len(),
+            Number::F64(n) => {
+                let s = n.to_string();
+                s.find('.').unwrap_or_else(|| s.len())
+            }
+        }
+    }
 }
 
 impl FromStr for Number {
@@ -440,13 +526,11 @@
     };
 
     let mut largest_dec = 0;
-    let mut padding = 0;
     let first = if numbers.len() > 1 {
         let slice = numbers[0];
         let len = slice.len();
         let dec = slice.find('.').unwrap_or(len);
         largest_dec = len - dec;
-        padding = dec;
         crash_if_err!(1, slice.parse())
     } else {
         Number::BigInt(BigInt::one())
@@ -456,7 +540,6 @@
         let len = slice.len();
         let dec = slice.find('.').unwrap_or(len);
         largest_dec = cmp::max(largest_dec, len - dec);
-        padding = cmp::max(padding, dec);
         crash_if_err!(1, slice.parse())
     } else {
         Number::BigInt(BigInt::one())
@@ -469,15 +552,18 @@
         );
         return 1;
     }
-    let last = {
+    let last: Number = {
         let slice = numbers[numbers.len() - 1];
-        padding = cmp::max(padding, slice.find('.').unwrap_or_else(|| slice.len()));
         crash_if_err!(1, slice.parse())
     };
     if largest_dec > 0 {
         largest_dec -= 1;
     }
 
+    let padding = first
+        .num_digits()
+        .max(increment.num_digits())
+        .max(last.num_digits());
     match (first, last, increment) {
         (Number::MinusZero, Number::BigInt(last), Number::BigInt(increment)) => print_seq_integers(
             (BigInt::zero(), increment, last),
@@ -617,12 +703,14 @@
         if !is_first_iteration {
             print!("{}", separator);
         }
+        let mut width = padding;
         if is_first_iteration && is_first_minus_zero {
             print!("-");
+            width -= 1;
         }
         is_first_iteration = false;
         if pad {
-            print!("{number:>0width$}", number = value, width = padding);
+            print!("{number:>0width$}", number = value, width = width);
         } else {
             print!("{}", value);
         }
@@ -633,5 +721,25 @@
         print!("{}", terminator);
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use crate::Number;
+    use num_bigint::{BigInt, Sign};
+
+    #[test]
+    fn test_number_num_digits() {
+        assert_eq!(
+            Number::BigInt(BigInt::new(Sign::Plus, vec![123])).num_digits(),
+            3
+        );
+        assert_eq!(
+            Number::BigInt(BigInt::new(Sign::Minus, vec![123])).num_digits(),
+            4
+        );
+        assert_eq!(Number::F64(123.45).num_digits(), 3);
+        assert_eq!(Number::MinusZero.num_digits(), 2);
+    }
+}
 
\ No newline at end of file diff --git a/uu_seq/fn.uu_app.html b/uu_seq/fn.uu_app.html index 1fdbbd6fd..6665400b9 100644 --- a/uu_seq/fn.uu_app.html +++ b/uu_seq/fn.uu_app.html @@ -1,3 +1,3 @@ uu_app in uu_seq - Rust -

Function uu_seq::uu_app[][src]

pub fn uu_app() -> App<'static, 'static>
\ No newline at end of file +

Function uu_seq::uu_app[][src]

pub fn uu_app() -> App<'static, 'static>
\ No newline at end of file diff --git a/uu_seq/fn.uumain.html b/uu_seq/fn.uumain.html index 0fe062b44..83ea557c0 100644 --- a/uu_seq/fn.uumain.html +++ b/uu_seq/fn.uumain.html @@ -1,3 +1,3 @@ uumain in uu_seq - Rust -

Function uu_seq::uumain[][src]

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

Function uu_seq::uumain[][src]

pub fn uumain(args: impl Args) -> i32
\ No newline at end of file diff --git a/uu_seq/index.html b/uu_seq/index.html index ec8d8ab34..6a581c571 100644 --- a/uu_seq/index.html +++ b/uu_seq/index.html @@ -1,4 +1,4 @@ uu_seq - Rust -

Crate uu_seq[][src]

Functions

+

Crate uu_seq[][src]

Functions

uu_app
uumain
\ No newline at end of file