v1.1.0 :: added autodetection for strings instead of requiring text flag for encoding and added encode as string override with text flag to pattern generation
This commit is contained in:
parent
a9e48d63d1
commit
117cead713
3 changed files with 18 additions and 14 deletions
28
src/main.rs
28
src/main.rs
|
|
@ -67,7 +67,13 @@ fn main() {
|
|||
if args.no_doll {
|
||||
println!("{}", generated);
|
||||
} else {
|
||||
match BigUint::parse_bytes(generated.as_bytes(), 10) {
|
||||
let as_num = if args.text {
|
||||
None
|
||||
} else {
|
||||
BigUint::parse_bytes(generated.as_bytes(), 10)
|
||||
};
|
||||
|
||||
match as_num {
|
||||
Some(num) => {
|
||||
println!("{} :: {}", generated, to_dollcode(num).unwrap());
|
||||
}
|
||||
|
|
@ -84,23 +90,21 @@ fn main() {
|
|||
}
|
||||
|
||||
if let Some(input) = args.encode {
|
||||
if args.text {
|
||||
let encode_as_text = args.text || input.parse::<BigUint>().is_err();
|
||||
|
||||
if encode_as_text {
|
||||
let result: Vec<String> = input
|
||||
.chars()
|
||||
.map(|c| to_dollcode(BigUint::from(c as u64)).unwrap())
|
||||
.collect();
|
||||
println!("{}", result.join(" "));
|
||||
} else {
|
||||
match input.parse::<BigUint>() {
|
||||
Ok(num) => match to_dollcode(num) {
|
||||
Ok(code) => println!("{}", code),
|
||||
Err(e) => {
|
||||
eprintln!("Error: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
eprintln!("Error: input must be a positive integer!");
|
||||
let num = input.parse::<BigUint>().unwrap();
|
||||
|
||||
match to_dollcode(num) {
|
||||
Ok(code) => println!("{}", code),
|
||||
Err(e) => {
|
||||
eprintln!("Error: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue