コード例 #1
0
ファイル: proftpdparser.cpp プロジェクト: PuppetFTP/PuppetFTP
ProftpdConfNode ProftpdParser::parse(const QString & data) const
{
    qDebug() << "data";
    qDebug() << data;
    qDebug() << "dataEND";

    ProftpdConfNode node;
    QRegExp beginNode(BEGIN_NODE_REGEXP, Qt::CaseSensitive, QRegExp::RegExp2);
    QRegExp datamatch(DATA_NODE_REGEXP, Qt::CaseSensitive, QRegExp::RegExp2);

    int childpos = 0;
    int datapos = 0;
    while ((childpos = beginNode.indexIn(data, childpos)) != -1) {

        while ((datapos = datamatch.indexIn(data, datapos)) != -1 && datapos < childpos) {
            datapos += datamatch.matchedLength() - 1;

            //    qDebug() << "DATAA" << data.right(datapos);
            if (datamatch.cap(1) == QLatin1String("Include"))
                continue;

            datamatch.cap(1).isEmpty() ?
            node.insert(datamatch.cap(3), QString())
            : node.insert(datamatch.cap(1), datamatch.cap(2));
        }

        childpos += beginNode.matchedLength() - 1;
        int beginData = childpos;
        QRegExp endNode(QString("(</%1>)").arg(beginNode.cap(1).isEmpty() ? beginNode.cap(3) : beginNode.cap(1)));
        childpos = endNode.indexIn(data, childpos);

        if (childpos == -1) {
            std::string err("Misformated configuration file");
            std::cerr << err << std::endl;
            throw ServerConfigHandler::ConfigurationException(err.c_str());
        }
        //      qDebug() << "ADD" << beginNode.capturedTexts();
        int endData = childpos;
        childpos += endNode.matchedLength();
        datapos = childpos;
        node.addChild(beginNode.cap(1).isEmpty() ? beginNode.cap(3) : beginNode.cap(1) + " " + beginNode.cap(2),
                      parse(data.mid(beginData).left(endData - beginData)));
    }
//   qDebug() << "DATAB" << data.right(datapos)<< "DATABEND";
    while ((datapos = datamatch.indexIn(data, datapos)) != -1) {
        datapos += datamatch.matchedLength() - 1;
        if (datamatch.cap(1) == QLatin1String("Include"))
            continue;

//       qDebug() << "DATA" << data.right(datapos) << "DATA END";
//qDebug() << datamatch.matchedLength() << datamatch.captureCount() << datamatch.capturedTexts();
        datamatch.cap(1).isEmpty() ?
        node.insert(datamatch.cap(3), QString())
        : node.insert(datamatch.cap(1), datamatch.cap(2));
    }

    return node;
}
コード例 #2
0
ファイル: Profile.cpp プロジェクト: tapio/Wendy
void Profile::beginNode(const char* name)
{
  ProfileNode* parent = m_stack.back();

  ProfileNode* node = parent->findChild(name);
  if (!node)
  {
    parent->m_children.push_back(ProfileNode(name));
    node = &(parent->m_children.back());
  }

  beginNode(*node);
}
コード例 #3
0
	//------------------------------
	bool NodeLoader::begin__node( const node__AttributeData& attributeData )
	{
		return beginNode(attributeData);
	}
コード例 #4
0
void VRMLFile::beginScript(const Char8 *szNodename)
{
    beginNode("Script", szNodename, TypeTraits<BitVector>::BitsClear);
}
コード例 #5
0
ファイル: Profile.cpp プロジェクト: tapio/Wendy
void Profile::beginFrame()
{
  resetNode(m_root);
  beginNode(m_root);
  m_timer.start();
}
コード例 #6
0
ファイル: proftpdparser.cpp プロジェクト: PuppetFTP/PuppetFTP
void insert(QString & data, QString key, const QString & value, bool toDelete)
{
    QStringList subkeys = key.split(QLatin1Char('#'));
    const QString & currentKey = subkeys.first();
    bool iscurrentKeyNode = (subkeys.count() > 1);

    QRegExp beginNode(BEGIN_NODE_REGEXP);
    QRegExp datamatch(DATA_NODE_REGEXP);

    int childpos = 0;
    int datapos = 0;
    while ((childpos = beginNode.indexIn(data, childpos)) != -1) {

        if (!iscurrentKeyNode) {
            while ((datapos = datamatch.indexIn(data, datapos)) != -1 && datapos < childpos) {
                if (datamatch.cap(1) == currentKey) {
                    if (toDelete) {
                        data.replace(datapos, datamatch.matchedLength(), QString());
                        return;
                    }

                    QString other = data.mid(datapos).left(datamatch.matchedLength()).replace(QRegExp(datamatch.cap(2)), value);
                    data.replace(datapos, datamatch.matchedLength(), other);
                    return;
                }

                if (datamatch.cap(3) == currentKey) {
                    if (toDelete) {
                        data.replace(datapos, datamatch.matchedLength(), QString());
                        return;
                    }

                    const QString other = data.mid(datapos).left(datamatch.matchedLength()) + QString("\t") + value;
                    data.replace(datapos, datamatch.matchedLength(), other);
                    return;
                }

                datapos += datamatch.matchedLength() - 1;
            }
        }

        childpos += beginNode.matchedLength() - 1;
        int beginData = childpos;
        QRegExp endNode(QString("(</%1>)").arg(beginNode.cap(1).isEmpty() ? beginNode.cap(3) : beginNode.cap(1)));
        childpos = endNode.indexIn(data, childpos);

        if (childpos == -1) {
            std::string err("Misformated configuration file");
            std::cerr << err << std::endl;
            throw ServerConfigHandler::ConfigurationException(err.c_str());
        }

        int endData = childpos;
        childpos += endNode.matchedLength();
        datapos = childpos;

        if ((currentKey.split(QString(" ")).first() == beginNode.cap(1) ||
                currentKey.split(QString(" ")).first() == beginNode.cap(3)) &&
                !subkeys.isEmpty()) {
            subkeys.removeFirst();
            QString inner = data.mid(beginData).left(endData - beginData);
            insert(inner, subkeys.join(QString("#")), value, toDelete);
            data.replace(beginData, endData - beginData, inner);
            return;
        }
    }

    if (iscurrentKeyNode) {
        data.prepend(QString("<%1>\n</%2>\n").arg(currentKey, currentKey.split(QString(" ")).first()));
        insert(data, subkeys.join(QString("#")), value, toDelete);
    } else {
        while ((datapos = datamatch.indexIn(data, datapos)) != -1) {
            if (datamatch.cap(1) == currentKey) {
                if (toDelete) {
                    data.replace(datapos, datamatch.matchedLength(), QString());
                    return;
                }

                const QString other = data.mid(datapos).left(datamatch.matchedLength()).replace(QRegExp(datamatch.cap(2)), value);
                data.replace(datapos, datamatch.matchedLength(), other);
                return;
            }

            if (datamatch.cap(3) == currentKey) {
                if (toDelete) {
                    data.replace(datapos, datamatch.matchedLength(), QString());
                    return;
                }

                const QString other = data.mid(datapos).left(datamatch.matchedLength()) + QString(" ") + value;
                data.replace(datapos, datamatch.matchedLength(), other);
                return;
            }

            datapos += datamatch.matchedLength() - 1;
        }

        if (toDelete)
            return;

        if (value.isEmpty())
            data.prepend(QString("\n%1").arg(key));
        else
            data.prepend(QString("\n%1\t%2").arg(key, value));
    }
}