From f6659579ec8f165db7f931eb05717f9f93ef27ef Mon Sep 17 00:00:00 2001 From: Reuben Thomas Date: Mon, 14 Jun 2021 15:22:33 +0100 Subject: [PATCH] pwl.c: allow the PWL APIs to be passed -1 as word length This is strictly an API/ABI change, but bump only the minor version, as in practice it is simply an extension that makes the enchant_pwl_* APIs work like the enchant_dict_* APIs. --- configure.ac | 2 +- src/pwl.c | 22 +++++++++++++++++----- src/pwl.h | 8 ++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 4877edc..e67163e 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([enchant],[2.2.15]) +AC_INIT([enchant],[2.3.0]) AC_CONFIG_SRCDIR(src/enchant.h) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([subdir-objects]) diff --git a/src/pwl.c b/src/pwl.c index 4f118a1..db645d5 100644 --- a/src/pwl.c +++ b/src/pwl.c @@ -313,8 +313,11 @@ static void enchant_pwl_remove_from_trie(EnchantPWL *pwl, } void enchant_pwl_add(EnchantPWL *pwl, - const char *const word, size_t len) + const char *const word, ssize_t len) { + if (len < 0) + len = strlen (word); + enchant_pwl_refresh_from_file(pwl); enchant_pwl_add_to_trie(pwl, word, len); @@ -342,7 +345,7 @@ void enchant_pwl_add(EnchantPWL *pwl, putc ('\n', f); } - if (fwrite (word, sizeof(char), len, f) == len) + if (fwrite (word, sizeof(char), len, f) == (size_t)len) { putc ('\n', f); } @@ -353,8 +356,11 @@ void enchant_pwl_add(EnchantPWL *pwl, } void enchant_pwl_remove(EnchantPWL *pwl, - const char *const word, size_t len) + const char *const word, ssize_t len) { + if (len < 0) + len = strlen (word); + if(enchant_pwl_check(pwl, word, len) == 1) return; @@ -525,8 +531,11 @@ static gchar* enchant_utf8_strtitle(const gchar*str, gssize len) return result; } -int enchant_pwl_check(EnchantPWL *pwl, const char *const word, size_t len) +int enchant_pwl_check(EnchantPWL *pwl, const char *const word, ssize_t len) { + if (len < 0) + len = strlen (word); + enchant_pwl_refresh_from_file(pwl); int exists = enchant_pwl_contains(pwl, word, len); @@ -609,8 +618,11 @@ static int best_distance(char** suggs, const char *const word, size_t len) /* gives the best set of suggestions from pwl that are at least as good as the * given suggs (if suggs == NULL just best from pwl) */ char** enchant_pwl_suggest(EnchantPWL *pwl, const char *const word, - size_t len, char** suggs, size_t* out_n_suggs) + ssize_t len, char** suggs, size_t* out_n_suggs) { + if (len < 0) + len = strlen (word); + int max_dist = suggs ? best_distance(suggs, word, len) : ENCHANT_PWL_MAX_ERRORS; max_dist = MIN (max_dist, ENCHANT_PWL_MAX_ERRORS); diff --git a/src/pwl.h b/src/pwl.h index f713b29..c945e3c 100644 --- a/src/pwl.h +++ b/src/pwl.h @@ -42,12 +42,12 @@ typedef struct str_enchant_pwl EnchantPWL; EnchantPWL* enchant_pwl_init(void); EnchantPWL* enchant_pwl_init_with_file(const char * file); -void enchant_pwl_add(EnchantPWL * me, const char *const word, size_t len); -void enchant_pwl_remove(EnchantPWL * me, const char *const word, size_t len); -int enchant_pwl_check(EnchantPWL * me,const char *const word, size_t len); +void enchant_pwl_add(EnchantPWL * me, const char *const word, ssize_t len); +void enchant_pwl_remove(EnchantPWL * me, const char *const word, ssize_t len); +int enchant_pwl_check(EnchantPWL * me, const char *const word, ssize_t len); /*gives the best set of suggestions from pwl that are at least as good as the given suggs*/ char** enchant_pwl_suggest(EnchantPWL *me, const char *const word, - size_t len, char ** suggs, size_t* out_n_suggs); + ssize_t len, char ** suggs, size_t* out_n_suggs); void enchant_pwl_free(EnchantPWL* me); #ifdef __cplusplus -- 2.42.0.windows.2