summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchenxiajian <chenxiajian1985@gmail.com>2011-08-13 07:16:10 +0000
committerchenxiajian <chenxiajian1985@gmail.com>2011-08-13 07:16:10 +0000
commit546bfcf577ed29e02e6ac8f7374da86078b997b8 (patch)
treeec753d4153fb67f97e2d71f8c5d47dcbca7d469e
parent53abc40a1c494eaa3e85e92e6f477c4dc9dd867f (diff)
downloadenchant-546bfcf577ed29e02e6ac8f7374da86078b997b8.tar.gz
match with name of abiword and name of Libhyphenation
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/branches/gsoc2011hyphenation@30184 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/ispell/Hyphenator.cpp4
-rw-r--r--src/ispell/Language.cpp1
-rw-r--r--src/ispell/Language.h5
-rw-r--r--src/ispell/ispell_checker.cpp63
-rw-r--r--src/ispell/ispell_checker.h7
5 files changed, 33 insertions, 47 deletions
diff --git a/src/ispell/Hyphenator.cpp b/src/ispell/Hyphenator.cpp
index 39ffcd5..75bced3 100644
--- a/src/ispell/Hyphenator.cpp
+++ b/src/ispell/Hyphenator.cpp
@@ -70,7 +70,9 @@ Hyphenate::Hyphenator::Hyphenator(const RFC_3066::Language& lang,string dicPath)
{
path = getenv("LIBHYPHENATE_PATH");
}
- path += "./language/";
+ else
+ path=dicPath;
+ path += "\\language\\";
string filename = lang.find_suitable_file(path);
dictionary = read_hyphenation_table(filename.c_str());
}
diff --git a/src/ispell/Language.cpp b/src/ispell/Language.cpp
index 5af0b03..94b39bb 100644
--- a/src/ispell/Language.cpp
+++ b/src/ispell/Language.cpp
@@ -45,7 +45,6 @@ Language::Language(string rfc_3066) throw(domain_error) {
throw *new domain_error("RFC 3066 tags must contain only letters, spaces "
+ string() + "and dashes.");
} while (*++c);
-
}
bool Language::operator==(const Language &o) const throw() {
diff --git a/src/ispell/Language.h b/src/ispell/Language.h
index 994a22f..4d5df88 100644
--- a/src/ispell/Language.h
+++ b/src/ispell/Language.h
@@ -24,7 +24,9 @@
#include <list>
#include <string>
#include <stdexcept>
-
+#include <map>
+#include <string>
+using namespace std;
namespace RFC_3066 {
/** This class implements a parser for RFC 3066-compliant language codes. */
class Language {
@@ -53,6 +55,7 @@ namespace RFC_3066 {
* first, then de-AT, then de. The directory should be /-postfixed. */
std::string find_suitable_file(const std::string &dir) const
throw(std::domain_error);
+ std::map<string,string> languageMap; //to match with name of abiword and name of Libhyphenation
};
}
diff --git a/src/ispell/ispell_checker.cpp b/src/ispell/ispell_checker.cpp
index aecf34c..bc61a00 100644
--- a/src/ispell/ispell_checker.cpp
+++ b/src/ispell/ispell_checker.cpp
@@ -67,42 +67,6 @@ static const IspellMap ispell_map [] = {
{"yi" ,"yiddish-yivo.hash" ,"utf-8" }
};
-static const IspellMap ispell_hyphenation_map [] = {
- {"ca" ,"en" ,"iso-8859-1" },
- {"cs" ,"czech.hash" ,"iso-8859-2" },
- {"da" ,"dansk.hash" ,"iso-8859-1" },
- {"de" ,"de" ,"iso-8859-1" },
- {"de_CH" ,"swiss.hash" ,"iso-8859-1" },
- {"el" ,"ellhnika.hash" ,"iso-8859-7" },
- {"en" ,"en" ,"iso-8859-1" },
- {"en_PH" ,"american.hash" ,"iso-8859-1" },
- {"en_US" ,"american.hash" ,"iso-8859-1" },
- {"eo" ,"esperanto.hash" ,"iso-8859-3" },
- {"es" ,"es" ,"iso-8859-1" },
- {"fi" ,"finnish.hash" ,"iso-8859-1" },
- {"fr" ,"fr" ,"iso-8859-1" },
- {"hu" ,"hungarian.hash" ,"iso-8859-2" },
- {"ga" ,"irish.hash" ,"iso-8859-1" },
- {"gl" ,"galician.hash" ,"iso-8859-1" },
- {"ia" ,"interlingua.hash" ,"iso-8859-1" },
- {"it" ,"italian.hash" ,"iso-8859-1" },
- {"la" ,"mlatin.hash" ,"iso-8859-1" },
- {"lt" ,"lietuviu.hash" ,"iso-8859-13" },
- {"nl" ,"nederlands.hash" ,"iso-8859-1" },
- {"nb" ,"norsk.hash" ,"iso-8859-1" },
- {"nn" ,"nynorsk.hash" ,"iso-8859-1" },
- {"no" ,"norsk.hash" ,"iso-8859-1" },
- {"pl" ,"polish.hash" ,"iso-8859-2" },
- {"pt" ,"brazilian.hash" ,"iso-8859-1" },
- {"pt_PT" ,"portugues.hash" ,"iso-8859-1" },
- {"ru" ,"russian.hash" ,"koi8-r" },
- {"sc" ,"sardinian.hash" ,"iso-8859-1" },
- {"sk" ,"slovak.hash" ,"iso-8859-2" },
- {"sl" ,"slovensko.hash" ,"iso-8859-2" },
- {"sv" ,"svenska.hash" ,"iso-8859-1" },
- {"uk" ,"ukrainian.hash" ,"koi8-u" },
- {"yi" ,"yiddish-yivo.hash" ,"utf-8" }
-};
static const size_t size_ispell_map = G_N_ELEMENTS(ispell_map);
@@ -154,12 +118,22 @@ ISpellChecker::ISpellChecker(EnchantBroker * broker)
{
memset(m_sflagindex,0,sizeof(m_sflagindex));
memset(m_pflagindex,0,sizeof(m_pflagindex));
+ initlanguageMap();//to match with name of abiword and name of Libhyphenation
}
#ifndef FREEP
#define FREEP(p) do { if (p) free(p); } while (0)
#endif
+void ISpellChecker::initlanguageMap()
+{
+ languageMap.insert(make_pair("en_US","en"));
+ languageMap.insert(make_pair("en","en"));
+ languageMap.insert(make_pair("de","de"));
+ languageMap.insert(make_pair("fr","fr"));
+ languageMap.insert(make_pair("es","es"));
+}
+
ISpellChecker::~ISpellChecker()
{
if (m_bSuccessfulInit) {
@@ -315,12 +289,16 @@ using namespace std;
char *
ISpellChecker::hyphenate(const char * const utf8Word, const char *const tag)
{ //we must choose the right language tag
- char* param_value = enchant_broker_get_param (m_broker, "enchant.ispell.hyphenation.dictionary.path");
- string result=Hyphenator(RFC_3066::Language(tag),param_value).hyphenate(utf8Word).c_str();
-
- char* temp=new char[result.length()];
- strcpy(temp,result.c_str());
- return temp;
+ char* param_value = enchant_broker_get_param (m_broker, "enchant.ispell.hyphenation.dictionary.path");
+ if(languageMap[tag]!="")
+ {
+ string result=Hyphenator(RFC_3066::Language(languageMap[tag]),param_value).hyphenate(utf8Word).c_str();
+
+ char* temp=new char[result.length()];
+ strcpy(temp,result.c_str());
+ return temp;
+ }
+ return NULL;
}
static GSList *
@@ -416,7 +394,6 @@ s_buildHashNames (std::vector<std::string> & names, EnchantBroker * broker, cons
g_slist_foreach (dirs, (GFunc)g_free, NULL);
g_slist_free (dirs);
}
-
char *
ISpellChecker::loadDictionary (const char * szdict)
{
diff --git a/src/ispell/ispell_checker.h b/src/ispell/ispell_checker.h
index 008e44f..6cf5453 100644
--- a/src/ispell/ispell_checker.h
+++ b/src/ispell/ispell_checker.h
@@ -5,7 +5,9 @@
#include <glib.h> // give glib a chance to override MAXPATHLEN first before it is set in ispell.h
#include "ispell.h"
#include "enchant.h"
-
+#include <map>
+#include <String>
+using namespace std;
class ISpellChecker
{
public:
@@ -239,6 +241,9 @@ private:
GIConv m_translate_in; /* Selected translation from/to Unicode */
GIConv m_translate_out;
+
+ std::map<string,string> languageMap; //to match with name of abiword and name of Libhyphenation
+ void initlanguageMap();
};
#endif /* ISPELL_CHECKER_H */