Guest User

Untitled

a guest
Jun 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. extern crate unicode_segmentation;
  2.  
  3. use unicode_segmentation::UnicodeSegmentation;
  4.  
  5.  
  6. fn pig_latin2(s: &str) -> String {
  7. let vowels = ["a", "e", "i", "o", "u"];
  8. let g = UnicodeSegmentation::graphemes(s, true).collect::<Vec<&str>>();
  9. if vowels.contains(&g[0]) {
  10. format!("{}{}", s, "-hay")
  11. } else {
  12. format!("{}{}{}{}", &s[1..], "-", &s[0..1], "ay")
  13. }
  14. }
  15.  
  16. fn pig_latin(s: &str) -> String {
  17. let first_letter = &s[0..1];
  18. let vowel_pig = format!("{}{}", s, "-hay");
  19.  
  20. match first_letter {
  21. "a" => vowel_pig,
  22. "e" => vowel_pig,
  23. "i" => vowel_pig,
  24. "o" => vowel_pig,
  25. "u" => vowel_pig,
  26. _ => format!("{}{}{}{}", &s[1..], "-", first_letter, "ay"),
  27. }
  28. }
  29.  
  30.  
  31. fn main() {
  32. println!("{}", pig_latin("first"));
  33. println!("{}", pig_latin("apple"));
  34. println!("{}", pig_latin2("first"));
  35. println!("{}", pig_latin2("apple"));
  36. }
Add Comment
Please, Sign In to add comment