use std::io;
fn get_content_input() -> String {
let mut content_input_str = String::new();
println!("Enter content in single line:");
io::stdin()
.read_line(&mut content_input_str)
.expect("Failed to read line");
content_input_str
}
fn get_first_and_rest_from_word(word: &str) -> (char, String) {
let mut rest_chars = String::new();
let mut iter = word.chars();
let first_char = iter.next().unwrap();
match first_char {
'a' | 'e' | 'i' | 'o' | 'u' | 'A' | 'E' | 'I' | 'O' | 'U' => ('_', word.to_string()),
'A'..='Z' | 'a'..='z' => {
for c in iter {
rest_chars.push(c);
}
(first_char, rest_chars)
}
_ => ('_', word.to_string())
}
}
fn append_ay(c: char) -> String {
match c {
'_' => "hay".to_string(),
'A'..='Z' | 'a'..='z' => c.to_string() + "ay",
_ => String::new()
}
}
fn main() {
let content_input = get_content_input();
let mut converted_content = String::new();
for word in content_input.split_whitespace() {
let (first_char, rest_chars) = get_first_and_rest_from_word(word);
converted_content.push_str(format!("{}-{} ", rest_chars, append_ay(first_char)).as_str())
}
println!("Converted to Pig latin: {}", converted_content.trim());
}