-
Notifications
You must be signed in to change notification settings - Fork 0
/
hanzisearch.cpp
39 lines (34 loc) · 1.03 KB
/
hanzisearch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "hanzisearch.h"
#include <QFile>
#include <QTextStream>
#include <QtConcurrentRun>
#include <qstringlist.h>
HanziSearch::HanziSearch()
{
QtConcurrent::run(this, &HanziSearch::loadData);
}
QString HanziSearch::getText(const QString &Hanzi)
{
return Hanzi.length() > 0 ? hash.value(Hanzi.at(0)) : QString();
}
void HanziSearch::loadData()
{
QFile file(":hanzitable.csv");
if(!file.open(QFile::ReadOnly))
{
qDebug("Error in HanziSearch::HanziSearch() : could not open file");
}
QTextStream in(&file);
in.setCodec("UTF-8");
while (!in.atEnd())
{
QString line = in.readLine();
QStringList cells = line.split(QChar(';'));
QString phrase;
for(int i = 2; i< cells.size(); ++i)
{
phrase += cells.at(i);
}
hash.insert(cells.first().simplified(), cells.at(1).simplified() + ": " + phrase.simplified());// do not use cells.last() because of some leading ;; characters in some rows
}
}