Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/uu/factor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ num-traits = { workspace = true } # used in src/numerics.rs, which is included b

[dependencies]
clap = { workspace = true }
itoa = { workspace = true }
num-traits = { workspace = true }
uucore = { workspace = true }
num-bigint = { workspace = true }
Expand Down
41 changes: 31 additions & 10 deletions src/uu/factor/src/factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,24 @@ fn write_result_u64(
print_exponents: bool,
) -> io::Result<()> {
write!(w, "{x}:")?;

let mut buf = itoa::Buffer::new();
for (factor, n) in factorization {
let factor_str = buf.format(factor);

if print_exponents {
w.write_all(b" ")?;
w.write_all(factor_str.as_bytes())?;

if n > 1 {
write!(w, " {factor}^{n}")?;
} else {
write!(w, " {factor}")?;
w.write_all(b"^")?;
w.write_all(buf.format(n).as_bytes())?;
}
} else {
w.write_all(format!(" {factor}").repeat(n).as_bytes())?;
for _ in 0..n {
w.write_all(b" ")?;
w.write_all(factor_str.as_bytes())?;
}
}
}
writeln!(w)?;
Expand All @@ -107,16 +116,26 @@ fn write_result_u128(
factorization: BTreeMap<u128, usize>,
print_exponents: bool,
) -> io::Result<()> {
write!(w, "{x}:")?;
let mut buf = itoa::Buffer::new();
w.write_all(buf.format(*x).as_bytes())?;
w.write_all(b":")?;

for (factor, n) in factorization {
let factor_str = buf.format(factor);

if print_exponents {
w.write_all(b" ")?;
w.write_all(factor_str.as_bytes())?;

if n > 1 {
write!(w, " {factor}^{n}")?;
} else {
write!(w, " {factor}")?;
w.write_all(b"^")?;
w.write_all(buf.format(n).as_bytes())?;
}
} else {
w.write_all(format!(" {factor}").repeat(n).as_bytes())?;
for _ in 0..n {
w.write_all(b" ")?;
w.write_all(factor_str.as_bytes())?;
}
}
}
writeln!(w)?;
Expand All @@ -139,7 +158,9 @@ fn write_result_big_uint(
write!(w, " {factor}")?;
}
} else {
w.write_all(format!(" {factor}").repeat(n).as_bytes())?;
for _ in 0..n {
write!(w, " {factor}")?;
}
}
}
writeln!(w)?;
Expand Down
4 changes: 2 additions & 2 deletions src/uu/numfmt/src/numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

pub fn uu_app() -> Command {
Command::new(uucore::util_name())
Command::new(util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
.help_template(uucore::localized_help_template(util_name()))
.about(translate!("numfmt-about"))
.after_help(translate!("numfmt-after-help"))
.override_usage(format_usage(&translate!("numfmt-usage")))
Expand Down
Loading