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


C++ QRegularExpressionMatch::lastCapturedIndex方法代码示例

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


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

示例1: readColorPattern

/**
 * Search for color pattern in given string
 * contentStr can also be JSON
 * returns pattern name if successful, or 'nil' if no pattern found
 * can be in form:
 *   pattern: policecar 
 *   pattern: "happy color dance"
 *   { "pattern": "red flashes" }
 * 
 * @param str string to parse
 * @return parsed color pattern name or empty string if no match
 */
QString DataInput::readColorPattern(QString str)
{
    QString patt;
    QRegularExpression   re("\"?pattern\"?:\\s*((\"(.+)\")|((.+)\\s))");
    QRegularExpressionMatch match = re.match(str);
    if( match.hasMatch() ) {
        patt = match.captured( match.lastCapturedIndex() );
    }
    return patt;
}
开发者ID:dunk8888,项目名称:blink1,代码行数:22,代码来源:datainput.cpp

示例2: readColorCode

/**
 * Read potential color code in string
 * @param str string to parse
 * @return valid QColor or invalid QColor if parsing failed
 */
QColor DataInput::readColorCode(QString str)
{
    QColor c;
    QRegularExpression re("(#[A-Fa-f0-9]{6})"); // look for "#cccccc" style hex colorcode
    QRegularExpressionMatch match = re.match(str);
    if( match.hasMatch() ) {
        c.setNamedColor( match.captured( match.lastCapturedIndex()) );
    }
    return c;
}
开发者ID:dunk8888,项目名称:blink1,代码行数:15,代码来源:datainput.cpp

示例3: readQmlTypes

QStringList readQmlTypes(const QString &filename) {
    QRegularExpression re("import QtQuick.tooling 1.2.*Module {\\s*dependencies:\\[([^\\]]*)\\](.*)}",
                          QRegularExpression::DotMatchesEverythingOption);
    if (!QFileInfo(filename).exists()) {
        std::cerr << "Non existing file: " << filename.toStdString() << std::endl;
        return QStringList();
    }
    QFile f(filename);
    if (!f.open(QFileDevice::ReadOnly)) {
        std::cerr << "Error in opening file " << filename.toStdString() << " : "
                  << f.errorString().toStdString() << std::endl;
        return QStringList();
    }
    QByteArray fileData = f.readAll();
    QString data(fileData);
    QRegularExpressionMatch m = re.match(data);
    if (m.lastCapturedIndex() != 2) {
        std::cerr << "Malformed file: " << filename.toStdString() << std::endl;
        return QStringList();
    }
    return m.capturedTexts();
}
开发者ID:2gis,项目名称:2gisqt5android,代码行数:22,代码来源:qmltypereader.cpp

示例4: computeEpisodeName

QString computeEpisodeName(const QString &article)
{
    const QRegularExpression episodeRegex = AutoDownloader::instance()->smartEpisodeRegex();
    const QRegularExpressionMatch match = episodeRegex.match(article);

    // See if we can extract an season/episode number or date from the title
    if (!match.hasMatch())
        return QString();

    QStringList ret;
    for (int i = 1; i <= match.lastCapturedIndex(); ++i) {
        QString cap = match.captured(i);

        if (cap.isEmpty())
            continue;

        bool isInt = false;
        int x = cap.toInt(&isInt);

        ret.append(isInt ? QString::number(x) : cap);
    }
    return ret.join('x');
}
开发者ID:einsteinsfool,项目名称:qBittorrent,代码行数:23,代码来源:rss_autodownloadrule.cpp

示例5: doReplaceNextMatch

void ReplaceMatches::doReplaceNextMatch()
{
    if ((!m_manager) || (m_cancelReplace) || (m_tree->topLevelItemCount() != 1)) {
        m_rootIndex = -1;
        emit replaceDone();
        return;
    }

    // NOTE The document managers signal documentWillBeDeleted() must be connected to
    // cancelReplace(). A closed file could lead to a crash if it is not handled.

    // Open the file
    QTreeWidgetItem *rootItem = m_tree->topLevelItem(0)->child(m_rootIndex);
    if (!rootItem) {
        m_rootIndex = -1;
        emit replaceDone();
        return;
    }

    if (!rootItem->data(0, ColumnRole).toString().isEmpty()) {
        // this is a search as you type replace
        rootItem = m_tree->topLevelItem(0);
        m_cancelReplace = true; // only one document...
    }

    if (rootItem->checkState(0) == Qt::Unchecked) {
        m_rootIndex++;
        emit replaceNextMatch();
        return;
    }

    KTextEditor::Document *doc;
    QString docUrl = rootItem->data(0, FileUrlRole).toString();
    QString docName = rootItem->data(0, FileNameRole).toString();
    if (docUrl.isEmpty()) {
        doc = findNamed(rootItem->data(0, FileNameRole).toString());
    }
    else {
        doc = m_manager->findUrl(QUrl::fromUserInput(docUrl));
        if (!doc) {
            doc = m_manager->openUrl(QUrl::fromUserInput(rootItem->data(0, FileUrlRole).toString()));
        }
    }

    if (!doc) {
        m_rootIndex++;
        emit replaceNextMatch();
        return;
    }

    QVector<KTextEditor::MovingRange*> rVector;
    QStringList rTexts;
    KTextEditor::MovingInterface* miface = qobject_cast<KTextEditor::MovingInterface*>(doc);
    int line;
    int column;
    int matchLen;
    int endLine;
    int endColumn;
    QTreeWidgetItem *item;
    QString matchLines;

    // lines might be modified so search the document again
    for (int i=0; i<rootItem->childCount(); i++) {
        item = rootItem->child(i);
        if (item->checkState(0) == Qt::Unchecked) continue;

        line = endLine= item->data(0, LineRole).toInt();
        column = item->data(0, ColumnRole).toInt();
        matchLen = item->data(0, MatchLenRole).toInt();
        matchLines = doc->line(line).mid(column);
        while (matchLines.size() < matchLen) {
            if (endLine+1 >= doc->lines()) break;
            endLine++;
            matchLines+= QLatin1Char('\n') + doc->line(endLine);
        }

        QRegularExpressionMatch match = m_regExp.match(matchLines);
        if (match.capturedStart() != 0) {
            qDebug() << matchLines << "Does not match" << m_regExp.pattern();
            continue;
        }

        QString replaceText = m_replaceText;
        replaceText.replace(QStringLiteral("\\\\"), QStringLiteral("¤Search&Replace¤"));

        // allow captures \0 .. \9
        for (int j = qMin(9, match.lastCapturedIndex()); j >= 0; --j) {
            replaceText.replace(QString(QStringLiteral("\\%1")).arg(j), match.captured(j));
        }

        // allow captures \{0} .. \{9999999}...
        for (int j = match.lastCapturedIndex(); j >= 0; --j) {
            replaceText.replace(QString(QStringLiteral("\\{%1}")).arg(j), match.captured(j));
        }

        replaceText.replace(QStringLiteral("\\n"), QStringLiteral("\n"));
        replaceText.replace(QStringLiteral("\\t"), QStringLiteral("\t"));
        replaceText.replace(QStringLiteral("¤Search&Replace¤"), QStringLiteral("\\"));
        rTexts << replaceText;

//.........这里部分代码省略.........
开发者ID:KDE,项目名称:kate,代码行数:101,代码来源:replace_matches.cpp

示例6: main


//.........这里部分代码省略.........
QRegularExpressionMatch match = re.match("abc", 0, QRegularExpression::PartialPreferFirstMatch);
bool hasMatch = match.hasMatch(); // false
bool hasPartialMatch = match.hasPartialMatch(); // true
//! [20]
}

{
//! [21]
QRegularExpression re("(abc)*");
QRegularExpressionMatch match = re.match("abc", 0, QRegularExpression::PartialPreferFirstMatch);
bool hasMatch = match.hasMatch(); // false
bool hasPartialMatch = match.hasPartialMatch(); // true
//! [21]
}

{
//! [22]
QRegularExpression invalidRe("(unmatched|parenthesis");
bool isValid = invalidRe.isValid(); // false
//! [22]
}

{
//! [23]
QRegularExpression invalidRe("(unmatched|parenthesis");
if (!invalidRe.isValid()) {
    QString errorString = invalidRe.errorString(); // errorString == "missing )"
    int errorOffset = invalidRe.patternErrorOffset(); // errorOffset == 22
    // ...
}
//! [23]
}

{
//! [24]
QRegularExpression re("^this pattern must match exactly$");
//! [24]
}

{
//! [25]
QString p("a .*|pattern");
QRegularExpression re("\\A(?:" + p + ")\\z"); // re matches exactly the pattern string p
//! [25]
}

{
//! [26]
QString escaped = QRegularExpression::escape("a(x) = f(x) + g(x)");
// escaped == "a\\(x\\)\\ \\=\\ f\\(x\\)\\ \\+\\ g\\(x\\)"
//! [26]
}

{
QString name;
QString nickname;
//! [27]
QString pattern = "(" + QRegularExpression::escape(name) +
                  "|" + QRegularExpression::escape(nickname) + ")";
QRegularExpression re(pattern);
//! [27]
}

{
QString string;
QRegularExpression re;
//! [28]
QRegularExpressionMatch match = re.match(string);
for (int i = 0; i <= match.lastCapturedIndex(); ++i) {
    QString captured = match.captured(i);
    // ...
}
//! [28]
}

{
//! [29]
QRegularExpression re("(\\d\\d) (?<name>\\w+)");
QRegularExpressionMatch match = re.match("23 Jordan");
if (match.hasMatch()) {
    QString number = match.captured(1); // first == "23"
    QString name = match.captured("name"); // name == "Jordan"
}
//! [29]
}

{
//! [30]
// extracts the words
QRegularExpression re("(\\w+)");
QString subject("the quick fox");
QRegularExpressionMatchIterator i = re.globalMatch(subject);
while (i.hasNext()) {
    QRegularExpressionMatch match = i.next();
    // ...
}
//! [30]
}

}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:101,代码来源:src_corelib_tools_qregularexpression.cpp

示例7: highlightBlock

void syntax_highlighter::highlightBlock(const QString &text)
{
	m_current_block = text;

	for (const auto& rule : m_multi_rules)
	{
		// Search for all the matching strings
		QRegularExpressionMatchIterator iter = rule.expression.globalMatch(m_current_block);

		// Iterate through the matching strings
		while (iter.hasNext())
		{
			// Apply formats to their respective found groups
			QRegularExpressionMatch match = iter.next();

			for (int i = 0; i <= match.lastCapturedIndex(); i++)
			{
				setFormat(match.capturedStart(i), match.capturedLength(i), rule.formats[i]);
			}
		}
	}

	for (const auto& rule : m_rules)
	{
		for (const auto& expression : rule.expressions)
		{
			// Search for all the matching strings
			QRegularExpressionMatchIterator iter = expression.globalMatch(m_current_block);
			bool contains_group = expression.captureCount() > 0;

			// Iterate through the matching strings
			while (iter.hasNext())
			{
				// Apply format to the matching string
				QRegularExpressionMatch match = iter.next();
				if (contains_group)
				{
					setFormat(match.capturedStart(1), match.capturedLength(1), rule.format);
				}
				else
				{
					setFormat(match.capturedStart(), match.capturedLength(), rule.format);
				}
			}
		}
	}

	for (const auto& rule : m_comment_rules)
	{
		int comment_start  = 0; // Current comment's start position in the text block
		int comment_end    = 0; // Current comment's end position in the text block
		int comment_length = 0; // Current comment length

		// We assume we end outside a comment until we know better
		setCurrentBlockState(block_state::ended_outside_comment);

		// Search for the first comment in this block if we start outside or don't want to search for multiline comments
		if (!rule.multi_line || previousBlockState() != block_state::ended_inside_comment)
		{
			comment_start = m_current_block.indexOf(rule.start_expression);
		}

		// Set format for the rest of this block/line
		if (!rule.multi_line)
		{
			comment_length = m_current_block.length() - comment_start;
			setFormat(comment_start, comment_length, rule.format);
			break;
		}

		// Format all comments in this block (if they exist)
		while (comment_start >= 0)
		{
			// Search for end of comment in the remaining text
			QRegularExpressionMatch match = rule.end_expression.match(m_current_block, comment_start);
			comment_end = match.capturedStart();
			match.captured(1);

			if (comment_end == -1)
			{
				// We end inside a comment and want to format the entire remaining text
				setCurrentBlockState(block_state::ended_inside_comment);
				comment_length = m_current_block.length() - comment_start;
			}
			else
			{
				// We found the end of the comment so we need to go another round
				comment_length = comment_end - comment_start + match.capturedLength();
			}

			// Set format for this text segment
			setFormat(comment_start, comment_length, rule.format);

			// Search for the next comment
			comment_start = m_current_block.indexOf(rule.start_expression, comment_start + comment_length);
		}
	}
}
开发者ID:Lexaundre,项目名称:rpcs3-test,代码行数:98,代码来源:syntax_highlighter.cpp

示例8: playground

void playground(QApplication& a)
{
	std::vector<int> l1 = { 0,1,3,6,9,11 };
	auto fromItem = std::upper_bound(l1.begin(), l1.end(), 2
		, [](const auto &a, const auto &b)
	{
		return a > b;
	});

	return;
	TextColorize::List _coloredTextParts;
	auto match = [&_coloredTextParts](const QString& text, Part::List& parts)
	{
		QRegularExpression::PatternOptions options;
		/*if (tc.caseSensitive == false)
		options |= QRegularExpression::PatternOption::CaseInsensitiveOption;
		*/
		QString rePattern;
		foreach(TextColorize ctp, _coloredTextParts) {
			QString pattern;
			if (ctp.caseSensitive == false)
				pattern += "(?i)";
			pattern += ctp.text;
			pattern.prepend("(").append(")");
			if(ctp.wordOnly)
				pattern.prepend("(?:^|[^\\w])").append("(?:[^\\w]|$)");
			rePattern += "|" + pattern;
		}
		rePattern = rePattern.mid(1);
		QRegularExpression re(rePattern, options);

		QRegularExpressionMatchIterator it = re.globalMatch(text);

		int nonMatchedStart = 0;
		bool hasMatches = it.hasNext();
		while (it.hasNext()) {
			QRegularExpressionMatch match = it.next();

			int matchedGroup = match.lastCapturedIndex();
			while (match.capturedTexts().at(matchedGroup).length() && --matchedGroup);

			qDebug()
				<< match.capturedTexts() << " - "
				<< match.capturedView() << " - "
				<< match.hasPartialMatch() << " - "
				<< matchedGroup;
			int nonMatechedEnd = match.capturedStart(0);
			


			int nonMatchedLength = nonMatechedEnd - nonMatchedStart;
			//auto& ct = _coloredTextParts[match.lastCapturedIndex() - 1];
			auto& ct = _coloredTextParts[0];
			if (nonMatchedLength)
				;// parts.push_back({ text.mid(nonMatchedStart, nonMatchedLength), nullptr });
			parts.push_back({ text.mid(match.capturedStart(0), match.capturedLength(0)), match.lastCapturedIndex() });
			nonMatchedStart = match.capturedEnd(0);
		}
		if (nonMatchedStart < text.length())
			parts.push_back({ text.mid(nonMatchedStart), false });
		return hasMatches;
	};
开发者ID:helkatz,项目名称:LogViewer,代码行数:62,代码来源:main.cpp

示例9: checkSystemInstallation


//.........这里部分代码省略.........
  // i.e. Actual Version of VirtualBox-Stable : 5.0.28 (<StableMajor>.<StableMinor>.<StableBugfix>)
  // i.e. Actual Version of VirtualBox-Current: 5.1.8  (<CurrentMajor>.<CurrentMinor>.<CurrentBugfix>)
  // -> 5.0.28: ok
  // -> 5.0.29: ok, log warning
  // -> 5.0.1: show warning: too old
  // -> 5.1.8: ok
  // -> 5.1.9: ok, log warning
  // -> 5.1.1: show warning: too old
  // -> 5.2.1: show warning: unsupported
  int  StableMajor = 5; int  StableMinor = 0; int  StableBugfix = 28;
  int CurrentMajor = 5; int CurrentMinor = 1; int CurrentBugfix = 8;

  // Supported Versions to show User i.e. "5.0.* + 5.1.*"
  QString supportedVersions;
  supportedVersions += QString::number(StableMajor);
  supportedVersions += ".";
  supportedVersions += QString::number(StableMinor);
  supportedVersions += ".* ";
  supportedVersions += QString::number(CurrentMajor);
  supportedVersions += ".";
  supportedVersions += QString::number(CurrentMinor);


  // the current version contains the subversion revision i.e.: 5.0.28r111378
  ILOG("installed VirtualBox version: " + vboxVersion);
  QRegularExpression regExpVboxVersion("^(\\d+)\\.(\\d+)\\.(\\d+).*$", QRegularExpression::MultilineOption);
  QRegularExpressionMatch match;

  bool showVersionUnsupported = false;
  bool showVersionToOld = false;
  bool showVersionToNew = false;
  QString vboxVersionStripped = vboxVersion;
  match = regExpVboxVersion.match(vboxVersion);
  if (match.lastCapturedIndex() == 3)
  {
    vboxVersionStripped = match.captured(1) + "." + match.captured(2) + "." + match.captured(3);
    if (match.captured(1).toInt() == StableMajor && match.captured(2).toInt() == StableMinor )
    {
      // VirtualBox-Stable detected
      if (match.captured(3).toInt() < StableBugfix)
      {
        showVersionToOld = true;
      }
      if (match.captured(3).toInt() > StableBugfix)
      {
        IWARN("Currently installed Bugfix-Version of VirtualBox-Stable is newer than the Verion tested by the PrivacyMachine-Team");
      }
    }
    else if (match.captured(1).toInt() == CurrentMajor && match.captured(2).toInt() == CurrentMinor )
    {
      // VirtualBox-Current detected
      if (match.captured(3).toInt() < CurrentBugfix)
      {
        showVersionToOld = true;
      }
      if (match.captured(3).toInt() > CurrentBugfix)
      {
        IWARN("Currently installed Bugfix-Version of VirtualBox-Current is newer than the Verion tested by the PrivacyMachine-Team");
      }
    }
    else if (match.captured(1).toInt() == CurrentMajor && match.captured(2).toInt() > CurrentMinor )
    {
      // Minor(API?) version is newer
      IWARN("Currently installed Version of VirtualBox-Current is newer than the Verion tested by the PrivacyMachine-Team");
      showVersionToNew = true;
    }
开发者ID:privacymachine,项目名称:src,代码行数:67,代码来源:main.cpp


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