void SpellCheckWorker::detectAffEncoding() { // detect encoding analyzing the SET option in the affix file QDir resourcesDir(getHunspellResourcesPath()); QString affPath = resourcesDir.absoluteFilePath(EN_HUNSPELL_AFF); m_Encoding = "ISO8859-1"; QFile affixFile(affPath); if (affixFile.open(QIODevice::ReadOnly)) { QTextStream stream(&affixFile); QRegExp encDetector("^\\s*SET\\s+([A-Z0-9\\-]+)\\s*", Qt::CaseInsensitive); for (QString line = stream.readLine(); !line.isEmpty(); line = stream.readLine()) { if (encDetector.indexIn(line) > -1) { m_Encoding = encDetector.cap(1); qDebug() << QString("Encoding of AFF set to ") + m_Encoding; break; } } affixFile.close(); } m_Codec = QTextCodec::codecForName(m_Encoding.toLatin1().constData()); }
void ToDoListView::ParseFile(const wxString& filename) { if (!wxFileExists(filename)) return; wxString st; LoaderBase* fileBuffer = Manager::Get()->GetFileManager()->Load(filename, true); if (fileBuffer) { EncodingDetector encDetector(fileBuffer); if (encDetector.IsOK()) { st = encDetector.GetWxStr(); ParseBuffer(st, filename); } } else return; delete fileBuffer; }