summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDom Lachowicz <domlachowicz@gmail.com>2006-04-02 14:01:47 +0000
committerDom Lachowicz <domlachowicz@gmail.com>2006-04-02 14:01:47 +0000
commitc31c99ef462a72977042c263fb3b0849f62e750b (patch)
tree6976697f41463b17cc227f95d9a87dd69ed4474f
parentd766a8dc85b962ccf110f9454549013070914e13 (diff)
downloadenchant-c31c99ef462a72977042c263fb3b0849f62e750b.tar.gz
optimize dict_exists in (especially) the ispell backend
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@21125 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/hspell/hspell_provider.c11
-rw-r--r--src/ispell/ispell_checker.cpp20
2 files changed, 30 insertions, 1 deletions
diff --git a/src/hspell/hspell_provider.c b/src/hspell/hspell_provider.c
index ee01a2b..3cd09fa 100644
--- a/src/hspell/hspell_provider.c
+++ b/src/hspell/hspell_provider.c
@@ -228,7 +228,7 @@ static char **
hspell_provider_list_dicts (EnchantProvider * me,
size_t * out_n_dicts)
{
- char * dictionary_path;
+ const char * dictionary_path;
char ** out_list = NULL;
*out_n_dicts = 0;
@@ -246,6 +246,14 @@ hspell_provider_list_dicts (EnchantProvider * me,
return out_list;
}
+static int
+hspell_provider_dictionary_exists (struct str_enchant_provider * me,
+ const char *const tag)
+{
+ (void)me;
+ return (!strcmp ("he", tag) || !strcmp ("he_IL", tag));
+}
+
static void
hspell_provider_free_string_list (EnchantProvider * me, char **str_list)
{
@@ -284,6 +292,7 @@ init_enchant_provider (void)
provider->dispose = hspell_provider_dispose;
provider->request_dict = hspell_provider_request_dict;
provider->dispose_dict = hspell_provider_dispose_dict;
+ provider->dictionary_exists = hspell_provider_dictionary_exists;
provider->identify = hspell_provider_identify;
provider->describe = hspell_provider_describe;
provider->list_dicts = hspell_provider_list_dicts;
diff --git a/src/ispell/ispell_checker.cpp b/src/ispell/ispell_checker.cpp
index e52d226..2155204 100644
--- a/src/ispell/ispell_checker.cpp
+++ b/src/ispell/ispell_checker.cpp
@@ -669,6 +669,25 @@ ispell_provider_list_dictionaries (EnchantProvider * me,
return out_dicts;
}
+static int
+ispell_provider_dictionary_exists (struct str_enchant_provider * me,
+ const char *const tag)
+{
+ std::string shortened_dict (tag);
+ size_t uscore_pos;
+ if ((uscore_pos = shortened_dict.rfind ('_')) != ((size_t)-1))
+ shortened_dict = shortened_dict.substr(0, uscore_pos);
+
+ for (size_t i = 0; i < size_ispell_map; i++)
+ {
+ const IspellMap * mapping = (const IspellMap *)(&(ispell_map[i]));
+ if (!strcmp (tag, mapping->lang) || !strcmp (shortened_dict.c_str(), mapping->lang))
+ return _ispell_provider_dictionary_exists(me, mapping->dict);
+ }
+
+ return 0;
+}
+
static void
ispell_provider_free_string_list (EnchantProvider * me, char **str_list)
{
@@ -704,6 +723,7 @@ init_enchant_provider (void)
provider->dispose = ispell_provider_dispose;
provider->request_dict = ispell_provider_request_dict;
provider->dispose_dict = ispell_provider_dispose_dict;
+ provider->dictionary_exists = ispell_provider_dictionary_exists;
provider->identify = ispell_provider_identify;
provider->describe = ispell_provider_describe;
provider->list_dicts = ispell_provider_list_dictionaries;