Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 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. match first_letter {
  19. "a" => format!("{}{}", s, "-hay"),
  20. "e" => format!("{}{}", s, "-hay"),
  21. "i" => format!("{}{}", s, "-hay"),
  22. "o" => format!("{}{}", s, "-hay"),
  23. "u" => format!("{}{}", s, "-hay"),
  24. _ => format!("{}{}{}{}", &s[1..], "-", first_letter, "ay"),
  25. }
  26. }
  27.  
  28.  
  29. fn main() {
  30. println!("{}", pig_latin("first"));
  31. println!("{}", pig_latin("apple"));
  32. println!("{}", pig_latin2("first"));
  33. println!("{}", pig_latin2("apple"));
  34. }
Add Comment
Please, Sign In to add comment