aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-12 09:36:10 +0200
committerMiquel Sabaté Solà <mssola@mssola.com>2025-10-27 10:29:19 +0100
commit6b098702c6f7df5d400b76031618506dbdda02a5 (patch)
treeb168c81c53ac30c04d839b7b4c5c54a93cbdb28b
parent83972171d712c60ddfaeb4a68ef1cfd8c314fc10 (diff)
downloadmihi-6b098702c6f7df5d400b76031618506dbdda02a5.tar.gz
mihi-6b098702c6f7df5d400b76031618506dbdda02a5.zip
Trim word parts on database insert
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
-rw-r--r--crates/cli/src/words.rs4
-rw-r--r--lib/mihi/src/lib.rs6
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<Word, String>
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<Word, String>
}
_ => 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<Word, String>
// 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,