Begin work on code

main
John Zacarias Jekel 1 year ago
parent e3624b4f74
commit 84f7889f9f
  1. 2
      .gitignore
  2. 8
      Cargo.toml
  3. 2
      LICENSE
  4. 86
      src/lib.rs

2
.gitignore vendored

@ -0,0 +1,2 @@
/target
/Cargo.lock

@ -0,0 +1,8 @@
[package]
name = "anslatortray"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

@ -1,6 +1,6 @@
MIT License
Copyright (c) <year> <copyright holders>
Copyright (c) 2022 John Jekel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@ -0,0 +1,86 @@
//!Anslatortray for Rust
//!
//!Welcome to the Anslatortray Documentation!
//!
//!A simple, Rust library to translate from English to Pig Latin.
//!
//!
//!<a href="https://en.wikipedia.org/wiki/Pig_Latin">Wikipedia's definition of Pig Latin</a> is "a language game or argot in which words in English are altered, usually by adding a fabricated suffix or by moving the onset or initial consonant or consonant cluster of a word to the end of the word and adding a vocalic syllable to create such a suffix."
//!
//!Essentially, the word is reorganized in an effort to hide its true meaning, which can be lots of fun!
//!The Anslatortray library can help out by converting any English text into Pig Latin quickly and easily.
//!
//!# Examples
//!
//!Try compiling this example code:
//!
//!```
//!//TODO example code
//!```
//!
//!# Useful Links
//!<a href="https://git.jekel.ca/JZJ/anslatortray-rs">Click here to visit the Anslatortray for Rust Git Repository!</a>.
//!
//!Anslatortray for Rust is a spiritual sucessor of the original <a href="https://git.jekel.ca/JZJ/anslatortray">Anslatortray</a> (for C++).
//!
//!# Anslatortray Code and Documentation Licence
//!MIT License
//!
//!Copyright (c) 2022 John Jekel
//!
//!Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//!
//!The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//!
//!THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
const VOWEL_START_STYLE: &str = "way";//TODO make this configurable via a Cargo feature
///Translates a multi-word string into Pig Latin!
pub fn translate(english: &str) -> String {
if english.is_empty() {
return "".to_string();
}
todo!();
}
///Translates a single word string into Pig Latin!
pub fn translate_word(english_word: &str) -> String {
if english_word.is_empty() {
return "".to_string();
}
let mut iterator = english_word.chars();
let first_char: char = iterator.next().unwrap();
if is_vowel(first_char) {
return english_word.to_string().push_str(VOWEL_START_STYLE);
}
todo!();
}
///Returns true if the paramter is a letter and a vowel, and false otherwise
pub fn is_vowel(letter: char) -> bool {
match letter {
'a' | 'e' | 'i' | 'o' | 'u' | 'A' | 'E' | 'I' | 'O' | 'U' => { return true; }
_ => { return false; }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_vowel() {
for letter in "aeiouAEIOU".chars() {
assert!(is_vowel(letter));
}
for letter in "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ".chars() {
assert!(!is_vowel(letter));
}
}
}
Loading…
Cancel
Save