Esempio n. 1
0
std::vector<BankAccount> OfxParser::parse()
{
    std::vector<BankAccount> result;
    QTextStream stream(m_file);
    QString line;
    QRegularExpression newTagMatcher("^<(\\w+)>$");
    QRegularExpression endTagMatcher("^</(\\w+)>$");
    QRegularExpression dataTagMatcher("^<(\\w+)>(.*)$");

    QStringList tagList;
    QMap<QString, QString> dataMap;
    while (stream.readLineInto(&line)) {
        if (line.isEmpty())
            continue;
        auto match = newTagMatcher.match(line);
        if (match.hasMatch()) {
            if (!dataMap.isEmpty()) {
                parsedData(result, tagList.join('/'), dataMap);
                dataMap.clear();
            }
            tagList.append(match.captured(1));
            continue;
        }
        match = endTagMatcher.match(line);
        if (match.hasMatch()) {
            if (!dataMap.isEmpty()) {
                parsedData(result, tagList.join('/'), dataMap);
                dataMap.clear();
            }
            tagList.pop_back();
            continue;
        }
        match = dataTagMatcher.match(line);
        if (match.hasMatch()) {
            dataMap.insert(match.captured(1), match.captured(2));
            continue;
        }
        qFatal("Invalid content");
    }
    return result;
}
Esempio n. 2
0
void TreeEditor::slotLoadedData()
 {
    QDomDocument doc;
    doc.setContent(m_reply->readAll());
    QDomElement root = doc.documentElement();
    QDomElement content = root.firstChildElement("InternetContent");
    QDomElement grabber = content.firstChildElement("grabber");

    while (!grabber.isNull())
    {
        QString title, author, image, description, type, commandline;
        double version;
        bool search = false;
        bool tree = false;

        title = grabber.firstChildElement("name").text();
        commandline = grabber.firstChildElement("command").text();
        author = grabber.firstChildElement("author").text();
        image = grabber.firstChildElement("thumbnail").text();
        type = grabber.firstChildElement("type").text();
        description = grabber.firstChildElement("description").text();
        version = grabber.firstChildElement("version").text().toDouble();

        QString treestring = grabber.firstChildElement("tree").text();

        if (!treestring.isEmpty() && (treestring.toLower() == "true" ||
            treestring.toLower() == "yes" || treestring == "1"))
            tree = true;

        QString searchstring = grabber.firstChildElement("search").text();

        if (!searchstring.isEmpty() && (searchstring.toLower() == "true" ||
            searchstring.toLower() == "yes" || searchstring == "1"))
            search = true;

        if (type.toLower() == "video" && tree)
        {
            LOG(VB_GENERAL, LOG_INFO,
                QString("Found Browseable Source %1...").arg(title));
            m_grabberList.append(new GrabberScript(title, image, VIDEO_FILE, author,
                        search, tree, description, commandline, version));
        }

        grabber = grabber.nextSiblingElement("grabber");
    }

    parsedData();
 }