implmented a decode to all standard bases flag
This commit is contained in:
parent
b68815c29c
commit
ca1e27a84e
3 changed files with 16 additions and 3 deletions
|
|
@ -69,7 +69,7 @@ pub fn run_encode(input: &str, base: u32, text: bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_decode(input: &str, base: u32, text: bool) {
|
pub fn run_decode(input: &str, base: u32, text: bool, all_bases: bool) {
|
||||||
let decode_as_text = text || input.split_whitespace().count() > 1;
|
let decode_as_text = text || input.split_whitespace().count() > 1;
|
||||||
|
|
||||||
if decode_as_text {
|
if decode_as_text {
|
||||||
|
|
@ -93,7 +93,16 @@ pub fn run_decode(input: &str, base: u32, text: bool) {
|
||||||
println!("{}", decoded_chars);
|
println!("{}", decoded_chars);
|
||||||
} else {
|
} else {
|
||||||
match from_dollcode(input) {
|
match from_dollcode(input) {
|
||||||
Ok(val) => println!("{}", val.to_str_radix(base)),
|
Ok(val) => {
|
||||||
|
if all_bases {
|
||||||
|
println!("bin :: {}", val.to_str_radix(2));
|
||||||
|
println!("oct :: {}", val.to_str_radix(8));
|
||||||
|
println!("dec :: {}", val.to_str_radix(10));
|
||||||
|
println!("hex :: {}", val.to_str_radix(16));
|
||||||
|
} else {
|
||||||
|
println!("{}", val.to_str_radix(base));
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Error: {}", e);
|
eprintln!("Error: {}", e);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,6 @@ fn main() {
|
||||||
} else if let Some(input) = args.encode {
|
} else if let Some(input) = args.encode {
|
||||||
commands::run_encode(&input, args.base.radix(), args.text);
|
commands::run_encode(&input, args.base.radix(), args.text);
|
||||||
} else if let Some(input) = args.decode {
|
} else if let Some(input) = args.decode {
|
||||||
commands::run_decode(&input, args.base.radix(), args.text);
|
commands::run_decode(&input, args.base.radix(), args.text, args.all_bases);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,10 @@ pub struct Args {
|
||||||
/// Input/output base for integers (2-36, or bin/oct/dec/hex/..)
|
/// Input/output base for integers (2-36, or bin/oct/dec/hex/..)
|
||||||
pub base: Base,
|
pub base: Base,
|
||||||
|
|
||||||
|
#[arg(long, default_value_t = false)]
|
||||||
|
/// Output result in binary, octal, decimal and hex
|
||||||
|
pub all_bases: bool,
|
||||||
|
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
/// Will generate codes without encoding it into dollcode
|
/// Will generate codes without encoding it into dollcode
|
||||||
pub no_doll: bool,
|
pub no_doll: bool,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue