diff --git a/src/uucore/src/lib/features/format/mod.rs b/src/uucore/src/lib/features/format/mod.rs index 0849ada15..d6db5e8c7 100644 --- a/src/uucore/src/lib/features/format/mod.rs +++ b/src/uucore/src/lib/features/format/mod.rs @@ -11,7 +11,7 @@ // spell-checker:ignore (vars) charf decf floatf intf scif strf Cninety mod spec; -mod num_format; +pub mod num_format; use spec::Spec; use std::{ diff --git a/src/uucore/src/lib/features/format/num_format.rs b/src/uucore/src/lib/features/format/num_format.rs index 75c18438c..3a27ac200 100644 --- a/src/uucore/src/lib/features/format/num_format.rs +++ b/src/uucore/src/lib/features/format/num_format.rs @@ -1,17 +1,60 @@ use std::io::Write; -use super::{ - spec::{ - Case, FloatVariant, ForceDecimal, NumberAlignment, PositiveSign, Prefix, UnsignedIntVariant, - }, - FormatError, -}; +use super::FormatError; pub trait Formatter { type Input; fn fmt(&self, writer: impl Write, x: Self::Input) -> Result<(), FormatError>; } +#[derive(Clone, Copy)] +pub enum UnsignedIntVariant { + Decimal, + Octal(Prefix), + Hexadecimal(Case, Prefix), +} + +#[derive(Clone, Copy)] + +pub enum FloatVariant { + Decimal, + Scientific, + Shortest, + Hexadecimal, +} + +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Case { + Lowercase, + Uppercase, +} + +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum Prefix { + No, + Yes, +} + +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum ForceDecimal { + No, + Yes, +} + +#[derive(Clone, Copy)] +pub enum PositiveSign { + None, + Plus, + Space, +} + +#[derive(Clone, Copy)] +pub enum NumberAlignment { + Left, + RightSpace, + RightZero, +} + pub struct SignedInt { pub width: usize, pub positive_sign: PositiveSign, @@ -87,6 +130,20 @@ pub struct Float { pub precision: usize, } +impl Default for Float { + fn default() -> Self { + Self { + variant: FloatVariant::Decimal, + case: Case::Lowercase, + force_decimal: ForceDecimal::No, + width: 0, + positive_sign: PositiveSign::None, + alignment: NumberAlignment::Left, + precision: 2, + } + } +} + impl Formatter for Float { type Input = f64; diff --git a/src/uucore/src/lib/features/format/spec.rs b/src/uucore/src/lib/features/format/spec.rs index 4a533d1e1..808969970 100644 --- a/src/uucore/src/lib/features/format/spec.rs +++ b/src/uucore/src/lib/features/format/spec.rs @@ -1,7 +1,10 @@ // spell-checker:ignore (vars) charf decf floatf intf scif strf Cninety use super::{ - num_format::{self, Formatter}, + num_format::{ + self, Case, FloatVariant, ForceDecimal, Formatter, NumberAlignment, PositiveSign, Prefix, + UnsignedIntVariant, + }, FormatArgument, FormatError, }; use std::{fmt::Display, io::Write}; @@ -36,54 +39,6 @@ pub enum Spec { }, } -#[derive(Clone, Copy)] -pub enum UnsignedIntVariant { - Decimal, - Octal(Prefix), - Hexadecimal(Case, Prefix), -} - -#[derive(Clone, Copy)] - -pub enum FloatVariant { - Decimal, - Scientific, - Shortest, - Hexadecimal, -} - -#[derive(Clone, Copy, PartialEq, Eq)] -pub enum Case { - Lowercase, - Uppercase, -} - -#[derive(Clone, Copy, PartialEq, Eq)] -pub enum Prefix { - No, - Yes, -} - -#[derive(Clone, Copy, PartialEq, Eq)] -pub enum ForceDecimal { - No, - Yes, -} - -#[derive(Clone, Copy)] -pub enum PositiveSign { - None, - Plus, - Space, -} - -#[derive(Clone, Copy)] -pub enum NumberAlignment { - Left, - RightSpace, - RightZero, -} - /// Precision and width specified might use an asterisk to indicate that they are /// determined by an argument. #[derive(Clone, Copy)] @@ -295,7 +250,8 @@ impl Spec { width, positive_sign, alignment, - }.fmt(writer, *i) + } + .fmt(writer, *i) } &Spec::UnsignedInt { variant,