~moshe-wagner/orayta/Orayta-QT

1 by moshe.wagner
Making the android branch into the main one
1
#include "book.h"
2
#include "guematria.h"
3
#include <QDebug>
4
5
void Book::BuildGuematriaDb()
6
{
7
    if (guematriaDbExists)
8
        return;
9
10
    GuematriaDb current;
11
12
    //Read book's contents
13
    QStringList text;
14
    //if (!ReadFileToList( mPath, text, "UTF-8", true))
15
    if (!ReadFileFromZip(mPath, "BookText", text, "UTF-8", true))
16
    {
17
        qDebug() << "Error reading the book's text" << mPath;
18
        return;
19
    }
20
21
    //If a line starts with one of these, it's a level sign
22
    QString levelSigns = "!@#$^~";
23
    //Any char not matchong this pattern, is no *pure* text.
24
    QRegExp notText("[^ א-ת]");
25
    //These are turned into spaces, and not just ignored.
26
    QString spaceSigns = "[-_:.,?]";
27
28
    for (int i=0; i < text.size(); i++)
29
    {
30
        //Level line
31
        if (levelSigns.contains(text[i][0]))
32
        {
33
            //Update iter
34
            //but if levelSign is '$' ???
35
            current.itr.SetLevelFromLine(text[i]);
36
        }
37
        //Text line
38
        else
39
        {
40
            //Turn קרי וכתיב into only קרי. Maybe this should be an option?
41
            text[i].replace( QRegExp ("[(][^)]*[)] [[]([^]]*)[]]"), "\\1");
42
43
            //Remove all non "pure-text" chars
44
            text[i].replace(QChar(0x05BE), " "); //Makaf
45
            text[i].replace(notText, "");
46
47
            //Remove double spaces and line breaks
48
            //and split in words
49
            current.words = text[i].simplified().split(' ');
50
51
            current.values.resize( current.words.size() );
52
            for (int n=0; n < current.words.size(); n++)
53
                current.values[n] = GematriaValueOfString(current.words[n]);
54
55
            guematriaDb.push_back( current );
56
        }
57
    }
58
59
60
    guematriaDbExists = true;
61
}
62
63
const vector <GuematriaDb>& Book::getGuematriaDb()
64
{
65
    BuildGuematriaDb();
66
    return guematriaDb;
67
}