Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SPELL_MANAGER_H
00021 #define SPELL_MANAGER_H
00022
00023
00024
00025
00026
00027 #ifndef UT_TYPES_H
00028 #include "ut_types.h"
00029 #endif
00030 #include "ut_string_class.h"
00031 #include "ut_vector.h"
00032 #include "ut_hash.h"
00033 #include "barbarisms.h"
00034
00035
00036 class SpellManager;
00037
00038 struct DictionaryMapping
00039 {
00040 UT_String lang;
00041 UT_String dict;
00042 UT_String enc;
00043 };
00044
00045 class ABI_EXPORT SpellChecker
00046 {
00047 friend class SpellManager;
00048
00049 public:
00050
00051 enum SpellCheckResult
00052 {
00053 LOOKUP_SUCCEEDED = 0,
00054 LOOKUP_FAILED = 1,
00055 LOOKUP_ERROR = 2
00056 };
00057
00058 SpellCheckResult checkWord(const UT_UCSChar* word, size_t len);
00059 UT_GenericVector<UT_UCSChar*>* suggestWord(const UT_UCSChar* word, size_t len);
00060
00061
00062 virtual UT_Vector & getMapping() {return m_vecEmpty;};
00063 virtual bool doesDictionaryExist (const char * ) {return false;};
00064 virtual bool addToCustomDict (const UT_UCSChar *word, size_t len);
00065
00066 virtual void correctWord (const UT_UCSChar *toCorrect, size_t toCorrectLen,
00067 const UT_UCSChar *correct, size_t correctLen);
00068
00069 virtual void ignoreWord (const UT_UCSChar *toCorrect, size_t toCorrectLen) = 0;
00070
00071 virtual bool isIgnored (const UT_UCSChar * pWord, size_t len) const = 0;
00072
00073 const UT_String& getLanguage () const
00074 {
00075 return m_sLanguage;
00076 }
00077
00078 bool requestDictionary (const char * szLang);
00079 bool isDictionaryFound(void)
00080 { return m_bFoundDictionary;}
00081 void setDictionaryFound(bool b)
00082 { m_bFoundDictionary = b;}
00083
00084 protected:
00085
00086 SpellChecker();
00087
00088 virtual ~SpellChecker();
00089
00090 void setLanguage (const char * lang)
00091 {
00092 m_sLanguage = lang;
00093 }
00094
00095 static void couldNotLoadDictionary ( const char * szLang );
00096
00097 UT_String m_sLanguage;
00098 BarbarismChecker m_BarbarismChecker;
00099 UT_Vector m_vecEmpty;
00100
00101 bool m_bIsBarbarism;
00102 bool m_bIsDictionaryWord;
00103 bool m_bFoundDictionary;
00104
00105 private:
00106 SpellChecker(const SpellChecker&);
00107 void operator=(const SpellChecker&);
00108
00109 virtual bool _requestDictionary (const char * szLang) = 0;
00110 virtual SpellCheckResult _checkWord(const UT_UCSChar* word, size_t len) = 0;
00111 virtual UT_GenericVector<UT_UCSChar*> *_suggestWord(const UT_UCSChar* word, size_t len) = 0;
00112 };
00113
00114 class ABI_EXPORT SpellManager
00115 {
00116 public:
00117 static SpellManager & instance (void);
00118
00119 virtual ~SpellManager ();
00120
00121
00122 virtual SpellChecker * lastDictionary (void) const;
00123 virtual SpellChecker * requestDictionary (const char * szLang);
00124 UT_uint32 numLoadedDicts () const { return m_nLoadedDicts; }
00125
00126 SpellChecker * getInstance() const;
00127
00128 private:
00129 SpellManager ();
00130 SpellManager ( const SpellManager & other );
00131 SpellManager & operator= ( const SpellManager & other );
00132
00133
00134 UT_StringPtrMap m_map;
00135 UT_String m_missingHashs;
00136 SpellChecker * m_lastDict;
00137 UT_uint32 m_nLoadedDicts;
00138 };
00139
00140 #endif