Improved window for detection of charset, but still doesn't solve cp1258 issue.

Originally committed to SVN as r1789.
This commit is contained in:
Rodrigo Braz Monteiro 2008-01-20 07:24:04 +00:00
parent 5ce231c09a
commit 8b8a93f560

View file

@ -42,6 +42,13 @@
#include <wx/choicdlg.h> #include <wx/choicdlg.h>
struct CharDetResult {
float confidence;
wxString name;
bool operator < (CharDetResult &par) { return confidence > par.confidence; }
};
//////////////// ////////////////
// Get encoding // Get encoding
wxString CharSetDetect::GetEncoding(wxString filename) { wxString CharSetDetect::GetEncoding(wxString filename) {
@ -58,23 +65,6 @@ wxString CharSetDetect::GetEncoding(wxString filename) {
// Flag as finished // Flag as finished
DataEnd(); DataEnd();
// Return whatever it got
return result;
}
struct CharDetResult {
float confidence;
wxString name;
bool operator < (CharDetResult &par) { return confidence > par.confidence; }
};
//////////
// Report
void CharSetDetect::Report(const char* aCharset) {
// Store the result reported
result = wxString(aCharset,wxConvUTF8);
// Grab every result obtained // Grab every result obtained
std::list<CharDetResult> results; std::list<CharDetResult> results;
for (int i=0;i<NUM_OF_CHARSET_PROBERS;i++) { for (int i=0;i<NUM_OF_CHARSET_PROBERS;i++) {
@ -82,8 +72,8 @@ void CharSetDetect::Report(const char* aCharset) {
for (int j=0;j<probes;j++) { for (int j=0;j<probes;j++) {
float conf = mCharSetProbers[i]->GetConfidence(j); float conf = mCharSetProbers[i]->GetConfidence(j);
// Only bother with those whose confidence is at least 5% // Only bother with those whose confidence is at least 1%
if (conf > 0.05f) { if (conf > 0.01f) {
results.push_back(CharDetResult()); results.push_back(CharDetResult());
results.back().name = wxString(mCharSetProbers[i]->GetCharSetName(j),wxConvUTF8); results.back().name = wxString(mCharSetProbers[i]->GetCharSetName(j),wxConvUTF8);
results.back().confidence = mCharSetProbers[i]->GetConfidence(j); results.back().confidence = mCharSetProbers[i]->GetConfidence(j);
@ -98,16 +88,34 @@ void CharSetDetect::Report(const char* aCharset) {
// Get choice from user // Get choice from user
int n = results.size(); int n = results.size();
wxArrayString choices; wxArrayString choices;
wxArrayString picked;
int i = 0;
for (std::list<CharDetResult>::iterator cur=results.begin();cur!=results.end();cur++) { for (std::list<CharDetResult>::iterator cur=results.begin();cur!=results.end();cur++) {
choices.Add(wxString::Format(_T("%f%% - "),(*cur).confidence*100.0f) + (*cur).name); wxString name = (*cur).name;
if (picked.Index(name) == wxNOT_FOUND) {
picked.Add(name);
choices.Add(wxString::Format(_T("%f%% - "),(*cur).confidence*100.0f) + name);
i++;
if (i == 20) break;
}
} }
int choice = wxGetSingleChoiceIndex(_("Aegisub could not narrow down the character set to a single one.\nPlease pick one below:"),_("Choose character set"),choices); int choice = wxGetSingleChoiceIndex(_("Aegisub could not narrow down the character set to a single one.\nPlease pick one below:"),_("Choose character set"),choices);
if (choice == -1) throw _T("Canceled"); if (choice == -1) throw _T("Canceled");
// Retrieve name // Retrieve name
int i = 0; i = 0;
for (std::list<CharDetResult>::iterator cur=results.begin();cur!=results.end();cur++,i++) { for (std::list<CharDetResult>::iterator cur=results.begin();cur!=results.end();cur++,i++) {
if (i == choice) result = (*cur).name; if (i == choice) result = (*cur).name;
} }
} }
// Return whatever it got
return result;
}
//////////
// Report
void CharSetDetect::Report(const char* aCharset) {
// Store the result reported
result = wxString(aCharset,wxConvUTF8);
} }