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 dpath = AegisubApp::folderName + _T("dictionaries/en_US.dic");
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() {
delete hunspell;
hunspell = NULL;
delete conv;
conv = NULL;
}
//////////////////////////
// Add word to dictionary
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
bool HunspellSpellChecker::CheckWord(wxString word) {
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) {
// Grab raw from Hunspell
char **results;
int n = hunspell->suggest(&results,word.mb_str(wxConvUTF8));
int n = hunspell->suggest(&results,word.mb_str(*conv));
// Convert each
for (int i=0;i<n;i++) {
wxString current(results[i],wxConvUTF8);
wxString current(results[i],*conv);
suggestions.Add(current);
delete results[i];
}

View File

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

View File

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

View File

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