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


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

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


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

示例1: getRegularExpression

QRegularExpression SearchOptions::getRegularExpression() const
{
  QRegularExpression regexp = isWildCard() ? StringUtil::wildCardToRegExp(getFindValue()) : QRegularExpression(getFindValue());
  if (!isCaseSensitive()) {
    regexp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
  }
  return regexp;
}
开发者ID:pitonyak,项目名称:ADPStampInventory,代码行数:8,代码来源:searchoptions.cpp

示例2: handleCurrentArticleChanged

// display a news
void RSSWidget::handleCurrentArticleChanged(const QModelIndex &currentIndex, const QModelIndex &previousIndex)
{
    m_ui->textBrowser->clear();

    if (previousIndex.isValid()) {
        RSS::Article *article = getArticlePtr(previousIndex);
        Q_ASSERT(article);
        article->markAsRead();
    }

    if (!currentIndex.isValid()) return;

    RSS::Article *article = getArticlePtr(currentIndex);
    Q_ASSERT(article);

    QString html;
    html += "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>";
    html += "<div style='background-color: #678db2; font-weight: bold; color: #fff;'>" + article->title() + "</div>";
    if (article->date().isValid())
        html += "<div style='background-color: #efefef;'><b>" + tr("Date: ") + "</b>" + article->date().toLocalTime().toString(Qt::SystemLocaleLongDate) + "</div>";
    if (!article->author().isEmpty())
        html += "<div style='background-color: #efefef;'><b>" + tr("Author: ") + "</b>" + article->author() + "</div>";
    html += "</div>";
    html += "<div style='margin-left: 5px; margin-right: 5px;'>";
    if (Qt::mightBeRichText(article->description())) {
        html += article->description();
    }
    else {
        QString description = article->description();
        QRegularExpression rx;
        // If description is plain text, replace BBCode tags with HTML and wrap everything in <pre></pre> so it looks nice
        rx.setPatternOptions(QRegularExpression::InvertedGreedinessOption
            | QRegularExpression::CaseInsensitiveOption);

        rx.setPattern("\\[img\\](.+)\\[/img\\]");
        description = description.replace(rx, "<img src=\"\\1\">");

        rx.setPattern("\\[url=(\")?(.+)\\1\\]");
        description = description.replace(rx, "<a href=\"\\2\">");
        description = description.replace("[/url]", "</a>", Qt::CaseInsensitive);

        rx.setPattern("\\[(/)?([bius])\\]");
        description = description.replace(rx, "<\\1\\2>");

        rx.setPattern("\\[color=(\")?(.+)\\1\\]");
        description = description.replace(rx, "<span style=\"color:\\2\">");
        description = description.replace("[/color]", "</span>", Qt::CaseInsensitive);

        rx.setPattern("\\[size=(\")?(.+)\\d\\1\\]");
        description = description.replace(rx, "<span style=\"font-size:\\2px\">");
        description = description.replace("[/size]", "</span>", Qt::CaseInsensitive);

        html += "<pre>" + description + "</pre>";
    }
    html += "</div>";
    m_ui->textBrowser->setHtml(html);
}
开发者ID:glassez,项目名称:qBittorrent,代码行数:58,代码来源:rsswidget.cpp

示例3: setRating

bool Ratings::setRating(const QString& val, RatingAgency ag)
{
    qint32 agencyIndex;

    for (agencyIndex = 0;; ++agencyIndex) {
        Q_ASSERT(agencyIndex <= CountRatingAcencies);
        if (static_cast<qint32>(ag) == (1 << agencyIndex))
            break;
    }
    /////////////////Fix for bloomberg return values in excel//////////////////
    if (val.trimmed().toUpper().left(4) == "#N/A") {
        setRating(RatingValue::NR, ag);
        setWatch(Stable, ag);
        return true;
    }
    //////////////////////////////////////////////////////////////////////////
    const  auto agencySyntax = RatingsPrivate::m_ratingSyntax[agencyIndex];
    QRegularExpression syntaxCheck;
    syntaxCheck.setPatternOptions(QRegularExpression::CaseInsensitiveOption | QRegularExpression::DontCaptureOption);
    for (int i = static_cast<qint16>(RatingValue::AAA); i <= static_cast<qint16>(RatingValue::Dm); ++i){
        if (!agencySyntax[i].isEmpty()) {
            syntaxCheck.setPattern(
                "(^|[^" + QRegularExpression::escape(RatingsPrivate::m_reservedChars[agencyIndex]) + "])"
                + QRegularExpression::escape(agencySyntax[i])
                + "($|[^" + QRegularExpression::escape(RatingsPrivate::m_reservedChars[agencyIndex]) + "])"
                );
            Q_ASSERT(syntaxCheck.isValid());
            if (syntaxCheck.match(val).hasMatch()){
                    setRating(static_cast<RatingValue>(i), ag);
                    break;
            }
        }
        if (i == static_cast<qint16>(RatingValue::Dm)) {
            setRating(RatingValue::NR, ag, Stable);
            return false;
        }
    }
    if (val.indexOf("*-", 0, Qt::CaseInsensitive) >= 0)
        setWatch(Negative, ag);
    else if (val.indexOf("*+", 0, Qt::CaseInsensitive) >= 0)
        setWatch(Positive, ag);
    else
        setWatch(Stable, ag);
    return true;
}
开发者ID:bubble501,项目名称:CLOModel,代码行数:45,代码来源:Ratings.cpp

示例4: api

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

	auto avProcess = [this](QNetworkReply *reply){
		Q_D(Post);
		Task &task = d->queue.head();
		switch (task.state){
		case None:{
			QString api("http://interface.%1/dmpost");
			api = api.arg(Utils::customUrl(Utils::Bilibili));
			task.request.setUrl(api);
			task.request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
			const Comment &c = task.comment;
			QUrlQuery params;
			params.addQueryItem("cid", QFileInfo(task.target->source).baseName());
			params.addQueryItem("date", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
			params.addQueryItem("pool", "0");
			params.addQueryItem("playTime", QString::number(c.time / 1000.0, 'f', 4));
			params.addQueryItem("color", QString::number(c.color));
			params.addQueryItem("fontsize", QString::number(c.font));
			params.addQueryItem("message", c.string);
			params.addQueryItem("rnd", QString::number(qrand()));
			params.addQueryItem("mode", QString::number(c.mode));
			task.data = QUrl::toPercentEncoding(params.query(QUrl::FullyEncoded), "%=&", "-.~_");
			emit stateChanged(task.state = Code);
			forward();
			break;
		}
		case Code:{
			int code = QString(reply->readAll()).toInt();
			if (code > 0){
				emit stateChanged(task.state = None);
			}
			else{
				emit stateChanged(task.state = code);
			}
			dequeue();
			break;
		}
		}
	};
	auto avRegular = [](QString code){
		static QRegularExpression r("a(v(\\d+([#_])?(\\d+)?)?)?");
		r.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
		return r.match(code).capturedLength() == code.length();
	};
	d->pool.append({ avRegular, 0, avProcess });

	auto ddProcess = [this](QNetworkReply *reply){
		Q_D(Post);
		Task &task = d->queue.head();
		switch (task.state){
		case None:{
			QString api("http://api.%1/api/v1/comment/%2");
			api = api.arg(Utils::customUrl(Utils::AcPlay));
			api = api.arg(QFileInfo(task.target->source).baseName());
			task.request.setUrl(api);
			task.request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
			const Comment &c = task.comment;
			QJsonObject params;
			params["Token"] = 0;
			params["Time"] = c.time / 1000.0;
			params["Mode"] = c.mode;
			params["Color"] = c.color;
			params["TimeStamp"] = QDateTime::currentMSecsSinceEpoch();
			params["Pool"] = 0;
			params["UId"] = 0;
			params["CId"] = 0;
			params["Message"] = c.string;
			task.data= QJsonDocument(params).toJson();
			emit stateChanged(task.state = Code);
			forward();
			break;
		}
		case Code:{
			const QJsonObject &result = QJsonDocument::fromJson(reply->readAll()).object();
			if (result["Success"].toBool()){
				emit stateChanged(task.state = None);
			}
			else{
				emit stateChanged(task.state = QNetworkReply::UnknownNetworkError);
			}
			dequeue();
			break;
		}
		}

	};
	auto ddRegular = [](QString code){
		static QRegularExpression r("d(d\\d*)?");
		r.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
		return r.match(code).capturedLength() == code.length();
	};
	d->pool.append({ ddRegular, 0, ddProcess });

	connect(this, &Post::stateChanged, [this](int code){
//.........这里部分代码省略.........
开发者ID:Kumangus,项目名称:BiliLocal,代码行数:101,代码来源:Post.cpp


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