当前位置: 首页>>代码示例>>C++>>正文


C++ QRegularExpression::globalMatch方法代码示例

本文整理汇总了C++中QRegularExpression::globalMatch方法的典型用法代码示例。如果您正苦于以下问题:C++ QRegularExpression::globalMatch方法的具体用法?C++ QRegularExpression::globalMatch怎么用?C++ QRegularExpression::globalMatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QRegularExpression的用法示例。


在下文中一共展示了QRegularExpression::globalMatch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: replaceInString

static QString replaceInString (const QRegularExpression &rx, QString string, T func) {
	QRegularExpressionMatchIterator it = rx.globalMatch (string);
	
	int offset = 0;
	while (it.hasNext ()) {
		QRegularExpressionMatch match = it.next ();
		QString replaceWith = func (match);
		
		int length = match.capturedLength ();
		int begin = match.capturedStart () + offset;
		string.replace (begin, length, replaceWith);
		offset += replaceWith.length () - length;
	}
	
	return string;
}
开发者ID:NuriaProject,项目名称:Network,代码行数:16,代码来源:restfulhttpnode.cpp

示例2: extensionsFromFilter

QStringList QgsFileUtils::extensionsFromFilter( const QString &filter )
{
  const QRegularExpression rx( QStringLiteral( "\\*\\.([a-zA-Z0-9]+)" ) );
  QStringList extensions;
  QRegularExpressionMatchIterator matches = rx.globalMatch( filter );

  while ( matches.hasNext() )
  {
    const QRegularExpressionMatch match = matches.next();
    if ( match.hasMatch() )
    {
      QStringList newExtensions = match.capturedTexts();
      newExtensions.pop_front(); // remove whole match
      extensions.append( newExtensions );
    }
  }
  return extensions;
}
开发者ID:CS-SI,项目名称:QGIS,代码行数:18,代码来源:qgsfileutils.cpp

示例3: splitoutCellReference

QStringList WorkbookParserPrivate::splitoutCellReference(QString expression) {
    QStringList result;
    QRegularExpression re = QRegularExpression(REGEX_CELL_REFERENCE_2);
    QRegularExpressionMatch match;
    int start, end = 0;

    QRegularExpressionMatchIterator it = re.globalMatch(expression);
    while (it.hasNext()) {
        match = it.next();
        start = match.capturedStart(0);
        result.append(expression.mid(end, start - end));
        // TODO replace cell references with actual contents of cell
        result.append(match.captured(0));
        // TODO above
        end = match.capturedEnd(0);
    }

    if (end < expression.length())
        result.append(expression.mid(end));

    return result;
}
开发者ID:simonmeaden,项目名称:workbook,代码行数:22,代码来源:workbookparser_p.cpp

示例4: linkify

QString linkify(const QString &input)
{
	// This regular expression is from: http://blog.mattheworiordan.com/post/13174566389/url-regular-expression-for-links-with-or-without-the
	static const QRegularExpression linkre(
		"((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[\\-;:&=\\+\\$,\\w][email protected])?[A-Za-z0-9\\.\\-]+|(?:www\\.|[\\-;:&=\\+\\$,\\w][email protected])[A-Za-z0-9\\.\\-]+)((?:\\/[\\+~%\\/\\.\\w\\-_]*)?\\?" "?(?:[\\-\\+=&;%@\\.\\w_]*)#?(?:[\\.\\!\\/\\\\\\w]*))?)"
		);

	static const QRegularExpression protore("^[a-zA-Z]{3,}:");

	auto matches = linkre.globalMatch(input);
	QString out;
	int pos=0;

	while(matches.hasNext()) {
		auto m = matches.next();
		QString url = m.captured();
		out.append(input.midRef(pos, m.capturedStart() - pos));
		pos = m.capturedEnd();

		out.append("<a href=\"");
		if(!protore.match(url).hasMatch())
			out.append("http://");
		out.append(url);
		out.append("\">");
		out.append(url);
		out.append("</a>");
	}

	// special case optimization: no matches
	if(pos==0)
		return input;

	out.append(input.midRef(pos));

	return out;
}
开发者ID:EvilKitty3,项目名称:Drawpile,代码行数:36,代码来源:html.cpp

示例5: parseAgent

DATA::Agent LiliHelper::parseAgent(const QString aPath, const QStringList aAliases, const QString aSheet)
{
    QXlsx::Document aDocument (aPath);
    DATA::Agent aAgent;

    QStringList aStringList;
    if (aSheet.length() != 0)
    {
        aStringList.append(aSheet);
    }
    else
    {
        aStringList = aDocument.sheetNames();
    }

    for (auto aSheet : aStringList)
    {
        aDocument.selectSheet(aSheet);
        QXlsx::CellRange aSheetRange (aDocument.dimension());

        QHash<QString, QDate> aRefDateMap;
        QDate aCurrentDate;
        QString aNote;
        for (int nRow = aSheetRange.firstRow(); nRow <= aSheetRange.lastRow(); ++nRow)
        {
            QVariant aCell = aDocument.read(nRow, 2);
            const bool bFirst = aCell.type() == QVariant::String && s_aWeekDays.contains(aCell.toString());

            if (bFirst)
            {
                if (aDocument.read(nRow, 19).type() == QVariant::String)
                {
                    aNote = aDocument.read(nRow, 19).toString();
                }

                QString aCellRef = QXlsx::CellReference (nRow, 9).toString();
                QVariant aDateVariant = aDocument.read(aCellRef);

                // Looking for date without reference
                if (!aCurrentDate.isValid() && aDateVariant.type() == QVariant::Date)
                {
                    aCurrentDate = aDateVariant.toDate();
                    aRefDateMap.insert(aCellRef, aCurrentDate);
                }

                // Looking for date with reference
                else if (aCurrentDate.isValid() && aDateVariant.type() == QVariant::String)
                {
                    QRegularExpression aRx;
                    QRegularExpressionMatchIterator aRxIterator;
                    aRx.setPattern("=(\\w+\\d+)\\+(\\d+)");

                    aRxIterator = aRx.globalMatch(aDateVariant.toString());

                    if (aRxIterator.hasNext())
                    {
                        QRegularExpressionMatch aMatch = aRxIterator.next();
                        QString aReferencedCell = aMatch.captured(1);
                        if (aRefDateMap.contains(aReferencedCell))
                        {
                            aCurrentDate = aRefDateMap[aReferencedCell].addDays(aMatch.captured(2).toInt());
                            aRefDateMap.insert(aCellRef, aCurrentDate);
                        }
                    }
                }

            }
            else if (aCurrentDate.isValid())
            {
                QVariant aNameVariant = aDocument.read(nRow, 1);
                if (aNameVariant.type() == QVariant::String && aAliases.contains(aNameVariant.toString()))
                {
                    int nHourHead = 2;
                    while (nHourHead <= 54)
                    {
                        QVariant aVariant = aDocument.read(nRow, nHourHead);
                        int nTempHead = nHourHead + 1;

                        if (aVariant.type() == QVariant::Double && aVariant.toInt() == 1)
                        {
                            QTime aStartTime (7, 0);
                            if (nHourHead > 2)
                            {
                                aStartTime = aStartTime.addSecs(1800 + (nHourHead - 3) * 900);
                            }
                            QTime aEndTime = aStartTime.addSecs(15 * 60);
                            aVariant = aDocument.read(nRow, nTempHead);
                            while (nTempHead <= 54 && aVariant.type() == QVariant::Double && aVariant.toInt() == 1)
                            {
                                aEndTime = aEndTime.addSecs(15 * 60);
                                ++nTempHead;
                                aVariant = aDocument.read(nRow, nTempHead);
                            }
                            aAgent.getEvents().append(DATA::CalEvent (QDateTime (aCurrentDate, aStartTime),
                                                                      QDateTime (aCurrentDate, aEndTime),
                                                                      aNote));
                        }

                        nHourHead = nTempHead;
                    }
//.........这里部分代码省略.........
开发者ID:Neirbo888,项目名称:lilicalendar,代码行数:101,代码来源:LiliHelper.cpp

示例6: url

Load::Load(QObject *parent) : QObject(parent), d_ptr(new LoadPrivate(this))
{
	Q_D(Load);
	ins = this;
	setObjectName("Load");

	auto avProcess = [this](QNetworkReply *reply){
		Q_D(Load);
		Task &task = d->queue.head();
		int sharp = task.code.indexOf(QRegularExpression("[#_]"));
		switch (task.state){
		case None:
		{
			QString i = task.code.mid(2, sharp - 2);
			QString p = sharp == -1 ? QString() : task.code.mid(sharp + 1);
			QString url("http://www.%1/video/av%2/");
			url = url.arg(Utils::customUrl(Utils::Bilibili)).arg(i);
			if (!p.isEmpty()){
				url += QString("index_%1.html").arg(p);
			}
			forward(QNetworkRequest(url), Page);
			break;
		}
		case Page:
		{
			d->model->clear();
			QString api, id, video(reply->readAll());
			int part = video.indexOf("<select");
			if (part != -1 && sharp == -1){
				QRegularExpression r("(?<=>).*?(?=</option>)");
				QStringRef list(&video, part, video.indexOf("</select>", part) - part);
				QRegularExpressionMatchIterator i = r.globalMatch(list);
				api = "http://www.%1/video/%2/index_%3.html";
				api = api.arg(Utils::customUrl(Utils::Bilibili));
				while (i.hasNext()){
					int index = d->model->rowCount() + 1;
					QStandardItem *item = new QStandardItem;
					item->setData(QUrl(api.arg(task.code).arg(index)), UrlRole);
					item->setData((task.code + "#%1").arg(index), StrRole);
					item->setData(Page, NxtRole);
					item->setData(Utils::decodeXml(i.next().captured()), Qt::EditRole);
					d->model->appendRow(item);
				}
			}
			if (d->model->rowCount() > 0){
				emit stateChanged(task.state = Part);
			}
			else{
				QRegularExpression r = QRegularExpression("cid[=\":]*\\d+", QRegularExpression::CaseInsensitiveOption);
				QRegularExpressionMatchIterator i = r.globalMatch(video);
				while (i.hasNext()){
					QString m = i.next().captured();
					m = QRegularExpression("\\d+").match(m).captured();
					if (id.isEmpty()){
						id = m;
					}
					else if (id != m){
						id.clear();
						break;
					}
				}
				if (!id.isEmpty()){
					api = "http://comment.%1/%2.xml";
					api = api.arg(Utils::customUrl(Utils::Bilibili));
					forward(QNetworkRequest(api.arg(id)), File);
				}
                else{
                    emit stateChanged(203);
                    qDebug() << "Fail to load danmaku, try biliApi";
                    dequeue();
                }
            }
			break;
		}
		case File:
		{
			dumpDanmaku(reply->readAll(), Utils::Bilibili, false);
			emit stateChanged(task.state = None);
			dequeue();
			break;
		}
		}
	};
	auto avRegular = [](QString &code){
		code.remove(QRegularExpression("/index(?=_\\d+\\.html)"));
		QRegularExpression r("a(v(\\d+([#_])?(\\d+)?)?)?");
		r.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
		return getRegular(r)(code);
	};
	d->pool.append({ avRegular, 0, avProcess });

	auto bbProcess = [this, avProcess](QNetworkReply *reply) {
		Q_D(Load);
		Task &task = d->queue.head();
		switch (task.state) {
		case None:
		{
			QString i = task.code.mid(2);
			QString u = "http://www.%1/bangumi/i/%2/";
			u = u.arg(Utils::customUrl(Utils::Bilibili)).arg(i);
//.........这里部分代码省略.........
开发者ID:FantasyNJ,项目名称:BiliLocal-OSX,代码行数:101,代码来源:Load.cpp


注:本文中的QRegularExpression::globalMatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。