summaryrefslogtreecommitdiffstats
path: root/src/rccspell.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2005-08-02 04:43:01 +0000
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2005-08-02 04:43:01 +0000
commit8b75f9bb6a09d54d634ff661655659951378aa2c (patch)
tree611f800f33ca919d37c724957fcc8c2b2bccb342 /src/rccspell.c
parente3f702e83a26468ee44f3f342a7a40a252f4603c (diff)
downloadlibrcc-8b75f9bb6a09d54d634ff661655659951378aa2c.tar.gz
librcc-8b75f9bb6a09d54d634ff661655659951378aa2c.tar.bz2
librcc-8b75f9bb6a09d54d634ff661655659951378aa2c.tar.xz
librcc-8b75f9bb6a09d54d634ff661655659951378aa2c.zip
Language autodetection
- rccConfigRecode function's are added - Language autodetection using aspell is added - Translation in 3 modes: "To English Language", "Skip English Translation", "Full" - Example2 to demonstrate translation possibilities
Diffstat (limited to 'src/rccspell.c')
-rw-r--r--src/rccspell.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/rccspell.c b/src/rccspell.c
new file mode 100644
index 0000000..c54e267
--- /dev/null
+++ b/src/rccspell.c
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "rccspell.h"
+
+rcc_speller rccSpellerCreate(const char *lang) {
+#ifdef HAVE_ASPELL
+ rcc_speller rccspeller;
+ AspellSpeller *speller = NULL;
+ AspellConfig *config;
+ AspellCanHaveError *possible_err;
+
+ if (!lang) return NULL;
+
+ rccspeller = (rcc_speller)malloc(sizeof(rcc_speller_s));
+ if (!rccspeller) return rccspeller;
+
+ config = new_aspell_config();
+
+ if (config) {
+ if (aspell_config_replace(config, "encoding", "utf-8")&&aspell_config_replace(config, "master", lang)) {
+ possible_err = new_aspell_speller(config);
+ if (aspell_error_number(possible_err) == 0) {
+ speller = to_aspell_speller(possible_err);
+ }
+ }
+ delete_aspell_config(config);
+ }
+
+ rccspeller->speller = speller;
+ return rccspeller;
+#else
+ return NULL;
+#endif /* HAVE_ASPELL */
+}
+
+void rccSpellerFree(rcc_speller rccspeller) {
+#ifdef HAVE_ASPELL
+ if ((rccspeller)&&(rccspeller->speller))
+ delete_aspell_speller(rccspeller->speller);
+ free(rccspeller);
+#endif /* HAVE_ASPELL */
+}
+
+int rccSpellerGetError(rcc_speller rccspeller) {
+ if ((!rccspeller)||(!rccspeller->speller)) return -1;
+ return 0;
+}
+
+int rccSpellerSized(rcc_speller speller, const char *word, size_t len) {
+#ifdef HAVE_ASPELL
+ int res;
+
+ if (rccSpellerGetError(speller)) return 0;
+ res = aspell_speller_check(speller->speller, word, len?len:-1);
+ return res<0?0:res;
+#endif /* HAVE_ASPELL */
+ return 0;
+}
+
+int rccSpeller(rcc_speller speller, const char *word) {
+ return rccSpellerSized(speller, word, 0);
+}