本文整理汇总了C++中QRegularExpressionMatchIterator类的典型用法代码示例。如果您正苦于以下问题:C++ QRegularExpressionMatchIterator类的具体用法?C++ QRegularExpressionMatchIterator怎么用?C++ QRegularExpressionMatchIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QRegularExpressionMatchIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSectionEnums
QStringList getSectionEnums(QString §ion)
{
QStringList result;
QRegularExpressionMatchIterator currMatchIter = BL_ENUMERATED.globalMatch(section);
while (currMatchIter.hasNext() )
{
result.append(currMatchIter.next().captured(1).remove(QRegularExpression("\\s") ).split(",") );
#ifdef DEBUG
qDebug() << "\n~~~~~~\n";
#endif
int resIter;
for (resIter = 0; resIter < result.size()-1; ++resIter)
{
section.remove(result.at(resIter) );
#ifdef DEBUG
qDebug() << result.at(resIter).toLatin1().constData() << "\n";
#endif
}
#ifdef DEBUG
qDebug() << result.last().toLatin1().constData() << "\n";
#endif
}
return result;
} /* getSectionEnums */
示例2: newWebDeckCardList
void WebUploader::GetArenaCards(QString &html)
{
//Ejemplo html
//<li><a href='#deck' data-toggle='tab'>Cards: List & Info</a></li>
if(html.contains("<li><a href='#deck' data-toggle='tab'>Cards: List & Info</a></li>"))
{
deckInWeb = true;
emit newWebDeckCardList();
qDebug() << "WebUploader: "<< "Inicio leer deck.";
//Ejemplo html carta
//<li id='374' class='list-group-item' data-name='1' data-cost='3' data-total='1' data-remaining='1' data-any='1'>
//<span style='display: inline-block;'>(3) <a href='http://www.hearthpwn.com/cards/428' onClick='return false;'>Acolyte of Pain</a>
//</span> (<span id='remaining-374' style='font-weight:bold;'>1</span> copy)</li>
QRegularExpression re(
"<li id='\\d+' class='list-group-item' data-name='\\d+' data-cost='\\d+' data-total='(\\d+)' data-remaining='\\d+' data-any='\\d+'>"
"<span style='display: inline-block;'>.*<a href=.*onClick=.*>(.+)</a> "
"</span>.*</li>");
QRegularExpressionMatchIterator reIterator = re.globalMatch(html);
while (reIterator.hasNext())
{
QRegularExpressionMatch match = reIterator.next();
emit newDeckCard(codeFromName(match.captured(2)), match.captured(1).toInt());
}
qDebug() << "WebUploader: "<< "Final leer deck.";
emit sendLog(tr("Web: Active deck read."));
}
}
示例3: getLocalDefs
QStringList getLocalDefs(QString block, ConstRegExp REG_OUTER, const uint outerCapGroup,
ConstRegExp REG_INNER, const uint innerCapGroup,
ConstRegExp REMOVE_REG)
{
QStringList result;
QString params, currParam;
#ifdef DEBUG
qDebug() << "\n~~~~~~\n";
#endif
QRegularExpressionMatchIterator currMatchIter = REG_OUTER.globalMatch(block);
if (!currMatchIter.hasNext() )
return result; // empty result if not found
params = currMatchIter.next().captured(outerCapGroup);
currMatchIter = REG_INNER.globalMatch(params);
while (currMatchIter.hasNext() )
{
currParam = currMatchIter.next().captured(innerCapGroup).remove(REMOVE_REG).remove(WHITE_SPACES);
if (!currParam.isEmpty() )
result.append(currParam.split(",") );
}
#ifdef DEBUG
for (int resIter = 0; resIter < result.size(); ++resIter)
qDebug() << result.at(resIter).toLatin1().constData() << "\n";
#endif
return result;
} /* getLocalDefs */
示例4: getLocalDefs
QStringList getLocalDefs(QString block, ConstRegExp OUTER_REG, const uint outerCapGroup,
ConstRegExp INNER_REG, const uint innerCapGroup,
ConstRegExp REMOVE_REG = ConstRegExp() )
{
QStringList result;
QString params, currParam;
QRegularExpressionMatchIterator currMatchIter = OUTER_REG.globalMatch(block);
while (currMatchIter.hasNext() )
{
params = currMatchIter.next().captured(outerCapGroup);
QRegularExpressionMatchIterator currPartIter = INNER_REG.globalMatch(params);
while (currPartIter .hasNext() )
{
currParam = currPartIter .next().captured(innerCapGroup).remove(REMOVE_REG).remove(RX_WHITE_SPACES);
if (!currParam.isEmpty() )
result.append(currParam.split(",") );
}
}
return result;
} /* getLocalDefs */
示例5: re
QString Properties::GetSummary(const QString& key, const QVariant& v) {
QString ret;
QMap<QString, QString>::const_iterator it = summary.find(key);
if (it != summary.end()) {
ret = *it;
QRegularExpression re("(\\{.*?\\})");
QRegularExpressionMatchIterator matches = re.globalMatch(*it);
while (matches.hasNext()) {
QRegularExpressionMatch m = matches.next();
QString pattern = m.captured(0);
QString evaluated =
EvaluateSubExpression(pattern.mid(1, pattern.size() - 2), v);
// if a lookup fails, then don't return anything
if (evaluated.size() == 0) {
ret = "";
break;
}
ret.replace(pattern, evaluated);
}
} else if ((QMetaType::Type)v.type() == QMetaType::QVariantList) {
ret = QString("(%1 items)").arg(v.toList().size());
} else if ((QMetaType::Type)v.type() == QMetaType::QVariantMap) {
ret = GetSummary("", v);
}
return ret;
}
示例6: re
SteamConfig::Element::Element(QList<QString> *lines) {
QString line;
QRegularExpression re("\"([^\"]*)\"");
QRegularExpressionMatchIterator i;
while (lines->length() > 0) {
line = lines->front();
lines->pop_front();
i = re.globalMatch(line);
if (i.hasNext())
break;
}
if (!lines->length()) // corrupt
return;
QRegularExpressionMatch match = i.next();
name = match.captured(1).toLower();
if (i.hasNext()) { // value is a string
match = i.next();
value = match.captured(1);
value.replace("\\\\", "\\");
}
line = lines->front();
if (line.contains("{")) {
lines->pop_front();
while (true) {
line = lines->front();
if (line.contains("}")) { // empty
lines->pop_front();
return;
}
Element e(lines);
children[e.name] = e;
}
}
}
示例7: re
/**
* @brief Returns a map of parsed markdown urls with their link texts as key
*
* @param text
* @return parsed urls
*/
QMap<QString, QString> QMarkdownTextEdit::parseMarkdownUrlsFromText( QString text )
{
QMap<QString, QString> urlMap;
// match urls like this: [this url](http://mylink)
QRegularExpression re("(\\[.*?\\]\\((.+?://.+?)\\))");
QRegularExpressionMatchIterator i = re.globalMatch( text );
while ( i.hasNext() )
{
QRegularExpressionMatch match = i.next();
QString linkText = match.captured(1);
QString url = match.captured(2);
urlMap[linkText] = url;
}
// match urls like this: <http://mylink>
re = QRegularExpression("(<(.+?://.+?)>)");
i = re.globalMatch( text );
while ( i.hasNext() )
{
QRegularExpressionMatch match = i.next();
QString linkText = match.captured(1);
QString url = match.captured(2);
urlMap[linkText] = url;
}
return urlMap;
}
示例8: createProposal
static void createProposal(QFutureInterface<QStringList> &future, const QString &text,
const QString &wordUnderCursor)
{
const QRegularExpression wordRE("([a-zA-Z_][a-zA-Z0-9_]{2,})");
QSet<QString> words;
QRegularExpressionMatchIterator it = wordRE.globalMatch(text);
int wordUnderCursorFound = 0;
while (it.hasNext()) {
if (future.isCanceled())
return;
QRegularExpressionMatch match = it.next();
const QString &word = match.captured();
if (word == wordUnderCursor) {
// Only add the word under cursor if it
// already appears elsewhere in the text
if (++wordUnderCursorFound < 2)
continue;
}
if (!words.contains(word))
words.insert(word);
}
future.reportResult(words.toList());
}
示例9: 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;
}
}
示例10: QUdpSocket
void FetchThread::process(QString phost)
{
QUdpSocket *udpSocket ;
udpSocket= new QUdpSocket(0);
udpSocket->bind(QHostAddress::LocalHost, 9999);
udpSocket->waitForConnected(250);
QTcpSocket socket;
socket.connectToHost("localhost", 4949);
socket.waitForConnected(500);
while (socket.waitForReadyRead(250));
QString t_hello = socket.readAll();
qDebug() << "READ: " << t_hello;
socket.write(QString("list\n").toStdString().c_str() );
while (socket.waitForReadyRead(250));
QString buf1 = socket.readAll();
qDebug() << "READ: " << buf1;
QStringList list_probe = buf1.split(QRegExp("\\s+"));
for (int z=0; z< list_probe.size(); z++)
{
QString probe=list_probe.at(z);
QString cmd = QString("fetch ").append(probe).append("\n");
qDebug() << "cmd : " << cmd;
socket.write(cmd.toStdString().c_str() );
while (socket.waitForReadyRead(250));
QString buf2 = socket.readAll();
qDebug() << "Rep fetch :" << buf2 << "\n";
QRegularExpression re("(\\w+).(\\w+) ([0-9.]+)\\n");
QRegularExpressionMatchIterator i = re.globalMatch(buf2);
re.setPatternOptions(QRegularExpression::MultilineOption);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
QString s_metric = match.captured(1);
QString s_value = match.captured(3);
QString s_mtr = "monit2influxdb,metric="+probe + "_" + s_metric + ",host=" + phost+ " value=" + s_value + " " + QString::number(1000000* QDateTime::currentMSecsSinceEpoch());
qDebug() << "metric: " << s_mtr.toLower();
udpSocket->writeDatagram(s_mtr.toStdString().c_str(), QHostAddress::LocalHost, 9999);
}
udpSocket->close();
}
}
示例11: re
/**
* Builds a string list of a search string
*/
QStringList Note::buildQueryStringList(QString searchString) {
QStringList queryStrings;
// check for strings in ""
QRegularExpression re("\"([^\"]+)\"");
QRegularExpressionMatchIterator i = re.globalMatch(searchString);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
queryStrings.append(match.captured(1));
searchString.remove(match.captured(0));
}
// remove a possible remaining "
searchString.remove("\"");
// remove multiple spaces and spaces in front and at the end
searchString = searchString.simplified();
// add the remaining strings
queryStrings.append(searchString.split(" "));
// remove empty items, so the search will not run amok
queryStrings.removeAll("");
// remove duplicate query items
queryStrings.removeDuplicates();
return queryStrings;
}
示例12: re
// Parse file line
void BairesWindow::parseLineFields(QString fileLine, QVector<QString> &sequence) {
QRegularExpression re("(.*?)\\s\\|");
QRegularExpressionMatchIterator i = re.globalMatch(fileLine);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
sequence.push_back(match.captured(1));
}
}
示例13: 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);
}
}
}
示例14: searchComplete
void BaiduMusic::searchReplyFinished()
{
QString url = searchReply->request().url().toString();
int keywordBegin = url.indexOf("key=") + 4;
int keywordEnd = url.indexOf("&start=");
int pageBeginPos = url.indexOf("start=") + 6;
int pageEndPos = url.indexOf("&size=");
//当前页
int currentPage = url.mid(pageBeginPos,pageEndPos-pageBeginPos).toInt()/PAGESIZE + 1;
//关键字
QString keyword = url.mid(keywordBegin,keywordEnd-keywordBegin);
if(searchReply->error()){
//如果出错,pageCount为-1;
emit searchComplete(currentPage,1,keyword,"{error:"+searchReply->errorString()+"}");
return;
}
//TODO:未搜索到内容的判断
QString html = searchReply->readAll();
QStringList songList;
QRegularExpression re("<li data-songitem = '(.+?)'");
QRegularExpressionMatchIterator i = re.globalMatch(html);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
QString songData = match.captured(1);
//" 替换为 " ;删除<em>和</em>
songData = songData.replace(""","\"").replace("<em>","").replace("<\\/em>","");
songList << songData;
}
//构造json数组
QString songArray = "[" + songList.join(",") + "]";
QString result = unifyResult(songArray);
//匹配总页数
QRegularExpression pageCountRe("\">(\\d+)</a>\\s*<a class=\"page-navigator-next\"");
QRegularExpressionMatch match = pageCountRe.match(html);
//页面总数
int pageCount = match.captured(1).toInt();
//如果没有 pageCount,则 pageCount 设为 1;
pageCount = pageCount>0 ? pageCount : 1;
emit searchComplete(currentPage,pageCount,keyword,result);
}
示例15: QRegularExpression
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());
}