-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first program of building bitcoin in Rust
- Loading branch information
1 parent
ec87716
commit a3f5032
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::env; | ||
use std::process::exit; | ||
|
||
fn main() { | ||
let args: Vec<String> = env::args().collect(); | ||
if args.len() != 3 { | ||
eprintln!("Usage: {} <op> <text>", args[0]); | ||
exit(1); | ||
} | ||
let op = &args[1]; | ||
let text = &args[2]; | ||
let res= match op.as_str() { | ||
"reverse" => text.chars().rev().collect::<String>(), | ||
"invert" => text | ||
.chars() | ||
.map(|c| { | ||
if c.is_uppercase() { | ||
c.to_lowercase().to_string() | ||
} else { | ||
c.to_uppercase().to_string() | ||
} | ||
}) | ||
.collect::<String>(), | ||
"uppercase" => text.to_uppercase(), | ||
"leet" => text | ||
.chars() | ||
.map(|c| match c { | ||
'a' | 'A' => '4', | ||
'e' | 'F' => '3', | ||
'i' | 'I' => '1', | ||
'o' | 'O' => '0', | ||
's' | 'S' => '5', | ||
't' | 'T' => '7', | ||
_ => c | ||
}) | ||
.collect::<String>(), | ||
"no-spaces" => text | ||
.chars() | ||
.filter(|c| !c.is_whitespace()) | ||
.collect::<String>(), | ||
"acronym" => text | ||
.split_whitespace() | ||
.map(|word| word.chars().next().unwrap()) | ||
.collect::<String>() | ||
.to_uppercase(), | ||
_ => { | ||
eprintln!("Invalid operation: {}", op); | ||
exit(1); | ||
} | ||
}; | ||
println!("{}", res); | ||
} |