Fixed thesaurus/spellchecker character set reading

Originally committed to SVN as r616.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-26 00:12:18 +00:00
parent 3e021fad29
commit 518c4d3766
4 changed files with 18 additions and 7 deletions

View file

@ -49,6 +49,8 @@ HunspellSpellChecker::HunspellSpellChecker() {
wxString affpath = AegisubApp::folderName + _T("dictionaries/en_US.aff"); wxString affpath = AegisubApp::folderName + _T("dictionaries/en_US.aff");
wxString dpath = AegisubApp::folderName + _T("dictionaries/en_US.dic"); wxString dpath = AegisubApp::folderName + _T("dictionaries/en_US.dic");
hunspell = new Hunspell(affpath.mb_str(wxConvLocal),dpath.mb_str(wxConvLocal)); hunspell = new Hunspell(affpath.mb_str(wxConvLocal),dpath.mb_str(wxConvLocal));
conv = NULL;
if (hunspell) conv = new wxCSConv(wxString(hunspell->get_dic_encoding(),wxConvUTF8));
} }
@ -57,13 +59,15 @@ HunspellSpellChecker::HunspellSpellChecker() {
HunspellSpellChecker::~HunspellSpellChecker() { HunspellSpellChecker::~HunspellSpellChecker() {
delete hunspell; delete hunspell;
hunspell = NULL; hunspell = NULL;
delete conv;
conv = NULL;
} }
////////////////////////// //////////////////////////
// Add word to dictionary // Add word to dictionary
void HunspellSpellChecker::AddWord(wxString word) { void HunspellSpellChecker::AddWord(wxString word) {
if (hunspell) hunspell->put_word(word.mb_str(wxConvUTF8)); if (hunspell) hunspell->put_word(word.mb_str(*conv));
} }
@ -71,7 +75,7 @@ void HunspellSpellChecker::AddWord(wxString word) {
// Check if the word is valid // Check if the word is valid
bool HunspellSpellChecker::CheckWord(wxString word) { bool HunspellSpellChecker::CheckWord(wxString word) {
if (!hunspell) return true; if (!hunspell) return true;
return (hunspell->spell(word.mb_str(wxConvUTF8)) == 1); return (hunspell->spell(word.mb_str(*conv)) == 1);
} }
@ -85,11 +89,11 @@ wxArrayString HunspellSpellChecker::GetSuggestions(wxString word) {
if (hunspell) { if (hunspell) {
// Grab raw from Hunspell // Grab raw from Hunspell
char **results; char **results;
int n = hunspell->suggest(&results,word.mb_str(wxConvUTF8)); int n = hunspell->suggest(&results,word.mb_str(*conv));
// Convert each // Convert each
for (int i=0;i<n;i++) { for (int i=0;i<n;i++) {
wxString current(results[i],wxConvUTF8); wxString current(results[i],*conv);
suggestions.Add(current); suggestions.Add(current);
delete results[i]; delete results[i];
} }

View file

@ -39,6 +39,7 @@
#include "setup.h" #include "setup.h"
#if USE_HUNSPELL == 1 #if USE_HUNSPELL == 1
#include "spellchecker.h" #include "spellchecker.h"
#include <wx/wxprec.h>
////////////// //////////////
@ -51,6 +52,7 @@ class Hunspell;
class HunspellSpellChecker : public SpellChecker { class HunspellSpellChecker : public SpellChecker {
private: private:
Hunspell *hunspell; Hunspell *hunspell;
wxCSConv *conv;
public: public:
HunspellSpellChecker(); HunspellSpellChecker();

View file

@ -47,6 +47,8 @@ MySpellThesaurus::MySpellThesaurus() {
wxString idxpath = AegisubApp::folderName + _T("dictionaries/th_en_US.idx"); wxString idxpath = AegisubApp::folderName + _T("dictionaries/th_en_US.idx");
wxString datpath = AegisubApp::folderName + _T("dictionaries/th_en_US.dat"); wxString datpath = AegisubApp::folderName + _T("dictionaries/th_en_US.dat");
mythes = new MyThes(idxpath.mb_str(wxConvLocal),datpath.mb_str(wxConvLocal)); mythes = new MyThes(idxpath.mb_str(wxConvLocal),datpath.mb_str(wxConvLocal));
conv = NULL;
if (mythes) conv = new wxCSConv(wxString(mythes->get_th_encoding(),wxConvUTF8));
} }
@ -55,6 +57,8 @@ MySpellThesaurus::MySpellThesaurus() {
MySpellThesaurus::~MySpellThesaurus() { MySpellThesaurus::~MySpellThesaurus() {
delete mythes; delete mythes;
mythes = NULL; mythes = NULL;
delete conv;
conv = NULL;
} }
@ -66,14 +70,14 @@ void MySpellThesaurus::Lookup(wxString word,ThesaurusEntryArray &result) {
// Grab raw from MyThes // Grab raw from MyThes
mentry *me; mentry *me;
wxCharBuffer buf = word.Lower().mb_str(wxConvUTF8); wxCharBuffer buf = word.Lower().mb_str(*conv);
int n = mythes->Lookup(buf,strlen(buf),&me); int n = mythes->Lookup(buf,strlen(buf),&me);
// Each entry // Each entry
for (int i=0;i<n;i++) { for (int i=0;i<n;i++) {
ThesaurusEntry entry; ThesaurusEntry entry;
entry.name = wxString(me[i].defn,wxConvUTF8); entry.name = wxString(me[i].defn,*conv);
for (int j=0;j<me[i].count;j++) entry.words.Add(wxString(me[i].psyns[j],wxConvUTF8)); for (int j=0;j<me[i].count;j++) entry.words.Add(wxString(me[i].psyns[j],*conv));
result.push_back(entry); result.push_back(entry);
} }

View file

@ -52,6 +52,7 @@ class MyThes;
class MySpellThesaurus: public Thesaurus { class MySpellThesaurus: public Thesaurus {
private: private:
MyThes *mythes; MyThes *mythes;
wxCSConv *conv;
public: public:
MySpellThesaurus(); MySpellThesaurus();