kiten/lib
linearEDICTFile.cpp
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
00021 #include "linearEDICTFile.h"
00022
00023 #include <kglobal.h>
00024 #include <kdebug.h>
00025 #include <kstandarddirs.h>
00026 #include <kprocess.h>
00027 #include <kapplication.h>
00028
00029 #include <QtCore/QTextCodec>
00030 #include <QtCore/QFile>
00031
00032
00033 linearEDICTFile::linearEDICTFile() :
00034 properlyLoaded(false)
00035 {
00036 }
00037
00038 linearEDICTFile::~linearEDICTFile()
00039 {
00040
00041 }
00042
00043 bool linearEDICTFile::loadFile(const QString& filename)
00044 {
00045 kDebug() << "Loading edict from " << filename << "\n";
00046
00047
00048 if (!edict.isEmpty())
00049 return true;
00050
00051 QFile file(filename);
00052 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
00053 return false;
00054
00055 QTextStream fileStream(&file);
00056 fileStream.setCodec(QTextCodec::codecForName("eucJP"));
00057
00058 QString lastLine;
00059 while (!fileStream.atEnd()) {
00060 lastLine = fileStream.readLine();
00061 if (lastLine[0] != '#') edict << lastLine;
00062 }
00063
00064 file.close();
00065 properlyLoaded = true;
00066
00067 return true;
00068 }
00069
00070 bool linearEDICTFile::valid() const
00071 {
00072 return properlyLoaded;
00073 }
00074
00076 QVector<QString> linearEDICTFile::findMatches(const QString &searchString) const
00077 {
00078
00079 QVector<QString> matches;
00080 foreach(const QString &it, edict) {
00081 if (it.contains(searchString))
00082 {
00083 matches.append(it);
00084 }
00085 }
00086 return matches;
00087
00088 }