diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f6397ec --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] +members = [ + "app", + "lib", +] +resolver = "3" + +[workspace.package] +edition = "2024" +authors = ["chodak166 "] +license = "MIT" \ No newline at end of file diff --git a/app/Cargo.toml b/app/Cargo.toml new file mode 100644 index 0000000..f6a49b8 --- /dev/null +++ b/app/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "mnemo-r" +version = "0.1.0" +edition = "2024" + +[dependencies] +clap = { version = "4.5.51", features = ["derive"] } +libmnemor = { path = "../lib" } + +[profile.release] +lto = true # Link Time Optimization: Analyzes entire program for optimizations +codegen-units = 1 # Forces single-threaded compilation (slower build, but smaller/faster binary) diff --git a/app/src/main.rs b/app/src/main.rs new file mode 100644 index 0000000..af5d737 --- /dev/null +++ b/app/src/main.rs @@ -0,0 +1,81 @@ +use clap::{Parser, ValueEnum}; + +#[derive(ValueEnum, Debug, Clone)] +enum System { + #[value(name = "major-en")] + MajorEn, + #[value(name = "major-pl")] + MajorPl, +} + +trait SystemEncoder { + fn encode(&self, word: &str) -> String; +} + +struct MajorEncoder { + dict: String, // TODO +} + +impl SystemEncoder for MajorEncoder { + fn encode(&self, word: &str) -> String { + let num_word: String = word + .chars() + .map(|c| c.to_digit(10).unwrap_or(0).to_string()) + .collect(); + format!("{}_{} -> {}", word, self.dict, num_word) + } +} + +fn create_encoder(system: &System) -> Box { + match system { + System::MajorPl => Box::new(MajorEncoder { + dict: String::from("dict-major-pl"), + }), + System::MajorEn => Box::new(MajorEncoder { + dict: String::from("dict-major-en"), + }), + } +} + +#[derive(Parser)] +#[command(author, version, about)] +struct CliArgs { + /// System name + #[arg(short, long, default_value = "major-pl")] + system: System, + + /// Encode given word + #[arg(short, long)] + encode: Option, + + /// List supported systems + #[arg(long)] + list_systems: bool, +} + +fn main() -> Result<(), Box> { + let args = CliArgs::parse(); + + if args.list_systems { + println!("Supported systems:"); + for system in System::value_variants() { + if let Some(possible_value) = system.to_possible_value() { + println!("- {}", possible_value.get_name()); + } + } + return Ok(()); + } + + if let Some(word) = args.encode { + println!( + "Encoding {} with system {:?}...", + word, + args.system.to_possible_value().unwrap().get_name() + ); + let encoder = create_encoder(&args.system); + let encoded_word = encoder.encode(&word); + println!("Encoded: [{}]", encoded_word); + } + + Ok(()) +} diff --git a/lib/Cargo.toml b/lib/Cargo.toml new file mode 100644 index 0000000..79650cf --- /dev/null +++ b/lib/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "libmnemor" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/lib/src/core/major_system_encoder.rs b/lib/src/core/major_system_encoder.rs new file mode 100644 index 0000000..e69de29 diff --git a/lib/src/core/traits/system_encoder.rs b/lib/src/core/traits/system_encoder.rs new file mode 100644 index 0000000..e69de29 diff --git a/lib/src/lib.rs b/lib/src/lib.rs new file mode 100644 index 0000000..d06c3d7 --- /dev/null +++ b/lib/src/lib.rs @@ -0,0 +1,28 @@ +pub struct TextProcessor { + prefix: String, +} + +impl TextProcessor { + /// Create a new processor with custom prefix + pub fn new(prefix: &str) -> Self { + Self { + prefix: prefix.to_string(), + } + } + + /// Process input text by adding prefix and converting to uppercase + pub fn process(&self, input: &str) -> String { + format!("{} {}", self.prefix, input.to_uppercase()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_processing() { + let processor = TextProcessor::new(">> "); + assert_eq!(processor.process("hello"), ">> HELLO"); + } +}