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


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

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


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

示例1: fix_self_closing_tags

// Handle the general case
QString GumboInterface::fix_self_closing_tags(const QString &source)
{
    QString newsource = source;
    QRegularExpression selfclosed("<\\s*([a-zA-Z]+)(\\s*[^>/]*)/\\s*>");
    QRegularExpressionMatch match = selfclosed.match(newsource, 0);
    while (match.hasMatch()) {
        if (match.capturedStart() == -1) {
            break;
        }
        QString tag = match.captured(0);
        int sp = match.capturedStart(0);
        int n = match.capturedLength(0);
        QString name = match.captured(1);
        QString atts = match.captured(2);;
        atts = atts.trimmed();
        if (!atts.isEmpty()) {
            atts = " " + atts;
        }
        int nsp = sp + n;
        if (!allowed_void_tags.contains(name)) {
            QString newtag = "<" + name + atts + "></" + name + ">";
            newsource = newsource.replace(sp,n,newtag);
            nsp = sp + newtag.length();
        }
        match = selfclosed.match(newsource, nsp);
    }
    return newsource;
}
开发者ID:CedarLogic,项目名称:Sigil,代码行数:29,代码来源:GumboInterface.cpp

示例2: Generate

// The actual generation engine
QString ShopTemplateManager::Generate(const Items &items) {
    QString temp = shopTemplate;
    {
        QRegularExpression expr("{(?<key>.+?)(?<options>(\\|(.+?))*?)}");
        QRegularExpressionMatchIterator matcher = expr.globalMatch(shopTemplate);
        int offset = 0;
        while (matcher.hasNext()) {
            QRegularExpressionMatch match = matcher.next();
            QString key = match.captured("key").toLower();
            int startPos = offset + match.capturedStart();
            int len = match.capturedLength();

            QStringList optionsAndData = match.captured("options").split("|", QString::SkipEmptyParts);
            QHash<QString, QString> options;
            for (QString optionAndData : optionsAndData) {
                int split = optionAndData.indexOf(":");
                if (split == -1) {
                    options.insert(optionAndData.toLower(), "");
                }
                else {
                    QString option = optionAndData.left(split).toLower();
                    QString data = optionAndData.mid(split + 1);
                    options.insert(option, data);
                }
            }

            QString replacement = FetchFromKey(key, items, &options);

            temp.replace(startPos, len, replacement);
            offset += replacement.length() - len;
        }
    }

    // Now clean up empty spoiler tags!
    int matches = -1;
    while (matches != 0){
        QRegularExpression expr("\\[spoiler=\\\"(?>.*?\\\"\\])(?>\\s*?\\[\\/spoiler\\]\\n)");
        QRegularExpressionMatchIterator matcher = expr.globalMatch(temp);
        int offset = 0;
        matches = 0;
        while (matcher.hasNext()) {
            QRegularExpressionMatch match = matcher.next();
            int startPos = match.capturedStart() + offset;
            int length = match.capturedLength();

            temp.remove(startPos, length);
            offset -= length;
            matches++;
        }
    }

    return temp;
}
开发者ID:Illviljan,项目名称:acquisitionplus,代码行数:54,代码来源:shoptemplatemanager.cpp

示例3: filterEntry

QList<LocatorFilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future,
                                                          const QString &entry)
{
    QList<LocatorFilterEntry> goodEntries;
    QList<LocatorFilterEntry> betterEntries;
    const EditorManager::FilePathInfo fp = EditorManager::splitLineAndColumnNumber(entry);

    const QRegularExpression regexp = createRegExp(fp.filePath);
    if (!regexp.isValid())
        return goodEntries;

    const QList<Entry> editorEntries = editors();
    for (const Entry &editorEntry : editorEntries) {
        if (future.isCanceled())
            break;
        QString fileName = editorEntry.fileName.toString();
        if (fileName.isEmpty())
            continue;
        QString displayName = editorEntry.displayName;
        const QRegularExpressionMatch match = regexp.match(displayName);
        if (match.hasMatch()) {
            LocatorFilterEntry filterEntry(this, displayName, QString(fileName + fp.postfix));
            filterEntry.extraInfo = FileUtils::shortNativePath(FileName::fromString(fileName));
            filterEntry.fileName = fileName;
            filterEntry.highlightInfo = highlightInfo(match);
            if (match.capturedStart() == 0)
                betterEntries.append(filterEntry);
            else
                goodEntries.append(filterEntry);
        }
    }
    betterEntries.append(goodEntries);
    return betterEntries;
}
开发者ID:choenig,项目名称:qt-creator,代码行数:34,代码来源:opendocumentsfilter.cpp

示例4: prepend_symbol_on_nth_match

/**
 * @brief prepend symbol on nth match
 * @param input input string
 * @param number_length the length of the number, will prepend symbol
 * if the length smaller than this number
 * @param nth the number of match
 * @param reg the pattern want to find
 * @param symbol symbol prepand before the number
 * @return the input after symbol prepend if match the condition; if the reg
 * found the match pattern but the target length less than number_length, do nothing;
 * if reg do not find any match, return "the number of match is out of range
 * or found no match in this string"
 */
QString prepend_symbol_on_nth_match(QString const &input, int number_length,
                                    int nth, const QRegularExpression &reg, QChar symbol)
{
    auto it = reg.globalMatch(input);
    QRegularExpressionMatch match;
    int count = 0;

    while (it.hasNext()){
        match = it.next();
        if(count == nth){
            if(match.hasMatch()){
                QString new_file_name = input;
                if(!match.captured(1).isEmpty()){
                    if(match.capturedLength(0) < number_length){
                        new_file_name.insert(match.capturedStart(0),
                                             QString(number_length - match.capturedLength(0),
                                                     symbol));
                    }
                }
                return new_file_name;
            }else{
                break;
            }
        }
        ++count;
    }

    return "the number of match is out of range or found no match in this string";
}
开发者ID:stereomatchingkiss,项目名称:QRenamer,代码行数:42,代码来源:stringUtility.cpp

示例5: isLineMatchingBackward

bool QuickFindPattern::isLineMatchingBackward(
        const QString& line, int column ) const
{
    int pos = 0;

    if ( ! active_ )
        return false;

    QRegularExpressionMatchIterator matches = regexp_.globalMatch(line);
    QRegularExpressionMatch lastMatch;
    while ( matches.hasNext() ) {
        QRegularExpressionMatch nextMatch = matches.peekNext();
        if ( column >= 0 && nextMatch.capturedEnd() >= column ) {
            break;
        }

        lastMatch = matches.next();
    }

    if ( lastMatch.hasMatch() ) {
        lastMatchStart_ = lastMatch.capturedStart();
        lastMatchEnd_ = lastMatch.capturedEnd() - 1;
        return true;
    }
    else {
        return false;
    }
}
开发者ID:Pac72,项目名称:glogg,代码行数:28,代码来源:quickfindpattern.cpp

示例6: parse

void HtmlParser::parse()
{
    while(!_downloaded)
    {
        QThread::msleep(10);
    }
    _info->_status = UrlInfo::PARSING;
    emit processing(_info.data());
    _info->_found = _content.contains(_text, Qt::CaseInsensitive);


    int start_offset = -1;
    QRegularExpression regExp("(?:https?|ftp)://(((((((((\\w|\\d)|\\055)|\\056)|\\046)|\\077)|\\043)|\\045)|\\057)|\\075)+");

    while (true)
    {
        QRegularExpressionMatch match = regExp.match(_content, ++start_offset);
        if (!match.hasMatch())
            break;
        start_offset = match.capturedStart();
        int end_offset = match.capturedEnd();
        _links << new HtmlParser(_content.mid(start_offset, end_offset), _text);
    }
    _content.clear();
    if (_downloader)
        delete _downloader;
    _downloader = nullptr;
    _info->_status = UrlInfo::FINISHED;
    emit processing(_info.data());
}
开发者ID:Varser,项目名称:HtmlParser,代码行数:30,代码来源:htmlparser.cpp

示例7: highlightBlock

void Highlighter::highlightBlock(const QString &text)
{
	foreach (const HighlightingRule &rule, highlightingRules)
	{
		QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
		while (matchIterator.hasNext())
		{
			QRegularExpressionMatch match = matchIterator.next();
			setFormat(match.capturedStart(), match.capturedLength(), rule.format);
		}
	}
开发者ID:AniLeo,项目名称:rpcs3,代码行数:11,代码来源:syntax_highlighter.cpp

示例8: highlightBlock

void SyntaxHighlighter::highlightBlock(const QString &text) {
  for (std::size_t i = 0; i < _keywords.size(); i++) {
    const KeywordRule &rule = _keywords.at(i);
    QRegularExpressionMatchIterator it = rule.rulePattern.globalMatch(text);
    while (it.hasNext()) {
      QRegularExpressionMatch match = it.next();
      setFormat(
          match.capturedStart(), match.capturedLength(), rule.ruleTextFormat);
    }
  }
}
开发者ID:TUM-LRR,项目名称:era-gp-sim,代码行数:11,代码来源:syntaxhighlighter.cpp

示例9: translate

void Template::translate(ITemplateTranslationProvider &provider)
{
	//This regex captures expressions of the form
	//<?= tr("This is a test") ?> and <?= tr("optional %1 parameters %2","bla","blu") ?>
	//The first capture group is the key (untranslated string), the second the optional list of parameters
	const QRegularExpression regexp = QRegularExpression("<\\?=\\s*tr\\(\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"((?:,\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\")*)\\s*\\)\\?>");
	//This one is used to extract the parameters using global matching
	const QRegularExpression paramExp = QRegularExpression(",\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"");

	int offset = 0;
	QRegularExpressionMatch match;
	do
	{
		match = regexp.match(*this,offset);

		if(match.hasMatch())
		{
			int start = match.capturedStart(0);
			int len = match.capturedLength(0);
			QString key = match.captured(1);

			//replace escaped double and single quotes
			key.replace("\\\"","\"");
			key.replace("\\'", "'");

			QString translation = provider.getTranslation(key);

			//find out if we have optional parameters
			if(match.capturedLength(2)>0)
			{
				QString params = match.captured(2);
				//extract each optional parameter
				QRegularExpressionMatchIterator it = paramExp.globalMatch(params);
				while(it.hasNext())
				{
					QRegularExpressionMatch paramMatch = it.next();
					QString param = paramMatch.captured(1);

					//replace escaped quotes
					param.replace("\\\"","\"");
					param.replace("\\'", "'");

					//apply the param
					translation = translation.arg(param);
				}
			}

			this->replace(start,len,translation);
			offset = start+translation.length();
		}
	}while(match.hasMatch());
}
开发者ID:PhiTheta,项目名称:stellarium,代码行数:52,代码来源:template.cpp

示例10: htmlEncode

QString StringUtils::htmlEncode(
    QString text, bool urlAsLinks, bool newlineAsBr) {
  QString s;
  QHash<int,int> linksIndexes; // start of link index -> length of link
  if (urlAsLinks) {
    QRegularExpressionMatchIterator it = linkRe.globalMatch(text);
    while (it.hasNext()) {
      QRegularExpressionMatch match = it.next();
      linksIndexes.insert(match.capturedStart(0), match.capturedLength(0));
    }
  }
  for (int i = 0; i < text.length(); ) {
    if (urlAsLinks && linksIndexes.contains(i)) {
      int l = linksIndexes.value(i);
      QString html = htmlEncode(text.mid(i, l), false), href = html;
      href.replace("\"", "%22");
      s.append("<a href=\"").append(href).append("\">").append(html)
          .append("</a>");
      i += l;
    } else {
      const QChar c = text.at(i);
      switch(c.toLatin1()) {
      case '<':
        s.append("&lt;");
        break;
      case '>':
        s.append("&gt;");
        break;
      case '&':
        s.append("&amp;");
        break;
      case '"':
        s.append("&#34;");
        break;
      case '\'':
        s.append("&#39;");
        break;
      case '\n':
        if (newlineAsBr)
          s.append("<br/>\n");
        else
          s.append(c);
        break;
      default:
        s.append(c);
      }
      ++i;
    }
  }
  return s;
}
开发者ID:g76r,项目名称:libqtssu,代码行数:51,代码来源:stringutils.cpp

示例11: foreach

    foreach (OnePartRule rule, onepartrules)
    {
        QRegularExpressionMatchIterator i = rule.pattern.globalMatch(text);

        while (i.hasNext())
        {
            QRegularExpressionMatch match = i.next();
            int length = match.capturedLength();
            if (length == 0)
                continue;
            int start = match.capturedStart();
            setFormat(start, length, rule.format);
        }
    }
开发者ID:cbmeeks,项目名称:PropellerIDE,代码行数:14,代码来源:highlighter.cpp

示例12: indexIn

int QzRegExp::indexIn(const QString &str, int offset) const
{
    QzRegExp* that = const_cast<QzRegExp*>(this);
    QRegularExpressionMatch m = match(str, offset);

    if (!m.hasMatch()) {
        that->m_matchedLength = -1;
        that->m_capturedTexts.clear();
        return -1;
    }

    that->m_matchedLength = m.capturedLength();
    that->m_capturedTexts = m.capturedTexts();
    return m.capturedStart();
}
开发者ID:Tasssadar,项目名称:qupzilla,代码行数:15,代码来源:qzregexp.cpp

示例13: test

bool HRProcessor::test(const Element &, const QString &block)
{
    //! No atomic grouping in python so we simulate it here for performance.
    //! The regex only matches what would be in the atomic group - the HR.
    //! Then check if we are at end of block or if next char is a newline.
    QRegularExpressionMatch m = this->SEARCH_RE.match(block);
    if ( m.hasMatch()
         && ( m.capturedEnd() == block.size()
              || block.at(m.capturedStart()+m.capturedLength()) == '\n' ) ) {
        //! Save match object on class instance so we can use it later.
        this->match = m;
        return true;
    }
    return false;
}
开发者ID:mugwort-rc,项目名称:QMarkdown,代码行数:15,代码来源:HRProcessor.cpp

示例14: isLineMatching

bool QuickFindPattern::isLineMatching( const QString& line, int column ) const
{
    if ( ! active_ )
        return false;

    QRegularExpressionMatch match = regexp_.match( line, column );
    if ( match.hasMatch() ) {
        lastMatchStart_ = match.capturedStart();
        lastMatchEnd_ = match.capturedEnd() - 1;
        return true;
    }
    else {
        return false;
    }
}
开发者ID:Pac72,项目名称:glogg,代码行数:15,代码来源:quickfindpattern.cpp

示例15: 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


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