From 6b098702c6f7df5d400b76031618506dbdda02a5 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 12 Aug 2025 09:36:10 +0200 Subject: Trim word parts on database insert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- crates/cli/src/words.rs | 4 +++- lib/mihi/src/lib.rs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/cli/src/words.rs b/crates/cli/src/words.rs index d387f00..ba86041 100644 --- a/crates/cli/src/words.rs +++ b/crates/cli/src/words.rs @@ -206,6 +206,7 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result else { return Err("abort!".to_string()); }; + let particle = particle.trim().to_string(); let categories = vec![ Category::Unknown, @@ -261,6 +262,7 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result } _ => None, }; + let kind = kind.trim().to_string(); // TODO: refine guess once the inflection is known: select from possible values. let kind = match category { @@ -366,7 +368,7 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result // from it, and insert it into the database. fn do_create(enunciated: String) -> Result<(), String> { let mut guess = get_initial_guess(enunciated.as_str()); - guess.enunciated = enunciated.clone(); + guess.enunciated = enunciated.trim().to_string(); let word = ask_for_word_based_on(enunciated.clone(), guess)?; match mihi::create_word(word) { diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs index 41a9953..36da6d2 100644 --- a/lib/mihi/src/lib.rs +++ b/lib/mihi/src/lib.rs @@ -402,12 +402,12 @@ pub fn create_word(word: Word) -> Result<(), String> { VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, \ datetime('now'), datetime('now'))", params![ - word.enunciated, - word.particle, + word.enunciated.trim(), + word.particle.trim(), word.language as usize, word.declension_id, word.conjugation_id, - word.kind, + word.kind.trim(), word.category as usize, word.regular, word.locative, -- cgit v1.2.3