本文整理汇总了C++中QRegExp::captureCount方法的典型用法代码示例。如果您正苦于以下问题:C++ QRegExp::captureCount方法的具体用法?C++ QRegExp::captureCount怎么用?C++ QRegExp::captureCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRegExp
的用法示例。
在下文中一共展示了QRegExp::captureCount方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: matchArgument
static void matchArgument (const QString &argument) {
// Regular expression for parsing "[name]=[value]"
static QRegExp rx ("[ \\t]*([a-z0-9\\.\\-_]+)[ \\t]*(\\+?\\=)(.*)", Qt::CaseInsensitive);
// Does it match?
if (rx.indexIn (argument) == 0 && rx.captureCount () == 3) {
QString name = rx.cap (1).toLower ();
if (rx.cap (2) == QLatin1String ("+=")) {
Nuria::VariableData data = g_data->variables.value (name);
if (!g_data->variables.contains (name))
data.append = true;
data.value += rx.cap (3);
g_data->variables.insert (name, data);
} else {
Nuria::VariableData data;
data.value = rx.cap (3);
data.append = false;
g_data->variables.insert (name, data);
}
}
}
示例2: fromFileName
QnxVersionNumber QnxVersionNumber::fromFileName(const QString &fileName, const QRegExp ®Exp)
{
QStringList segments;
if (regExp.exactMatch(fileName) && regExp.captureCount() == 1)
segments << regExp.cap(1).split(QLatin1Char('_'));
return QnxVersionNumber(segments);
}
示例3: emitMagSwipe
void Interceptor::emitMagSwipe(const QRegExp ®Exp, bool track1, bool track2, bool track3) const {
Logger log("void Interceptor::tryEmitMagSwipe(const QRegExp ®Exp) const");
// It is assumed that the caller has confirmed match on the regexp, and that it matches the tracks.
QString track1value;
QString track2value;
QString track3value;
int captures = regExp.captureCount();
int nextCapture = 1;
if ( track1 && nextCapture <= captures ) {
track1value = regExp.cap( nextCapture );
nextCapture += 1;
}
if ( track2 && nextCapture <= captures ) {
track2value = regExp.cap( nextCapture );
nextCapture += 1;
}
if ( track3 && nextCapture <= captures ) {
track3value = regExp.cap( nextCapture );
nextCapture += 1;
}
log.stream() << "Number of captures : " << captures;
log.stream() << "Track1 : '" << track1value << "'";
log.stream() << "Track2 : '" << track2value << "'";
log.stream() << "Track3 : '" << track3value << "'";
if ( track1value.toUpper() == "E"
|| track2value.toUpper() == "E"
|| track3value.toUpper() == "E" ) {
log.stream( warn ) << "Failed to read one or more tracks during a magswipe";
emit magSwipeFailure();
return;
}
// Figure out if this is a DK Sundhedskort.
if ( track1 && track2 && !track3 ) {
log.stream() << "Checking 2 track (1,2) card";
log.stream() << "Mabbe it is a DKSundhedskort";
try {
emit magSwipe( DKSundhedskort( track1value, track2value ) );
return;
} catch ( ... ) {
log.stream( debug ) << "Probably not a DKSundhedskort";
}
log.stream() << "Mabbe it is a CreditCard";
try {
emit magSwipe( CreditCard( track1value, track2value ) );
return;
} catch ( ... ) {
log.stream( debug ) << "Probably not a CreditCard";
}
log.stream( warn ) << "Found two tracks on mag card, but did not match any known card layout.";
emit magSwipeFailure();
return;
}
// Reaching here is an error, but we only log a warning, as we clealy do not understand all cards...
log.stream( warn ) << "Totalmatch, but no card match found.";
emit magSwipeFailure();
}
示例4: groupValue
QString ModelGrouper::groupValue( const QModelIndex & idx )
{
QRegExp regEx = columnGroupRegex(mGroupColumn);
QString strValue = model()->data( idx.column() == mGroupColumn ? idx : idx.sibling(idx.row(),mGroupColumn), Qt::DisplayRole ).toString();
if( !regEx.isEmpty() && regEx.isValid() && strValue.contains(regEx) )
strValue = regEx.cap(regEx.captureCount() > 1 ? 1 : 0);
//LOG_5( QString("Index %1 grouped with value %2").arg(indexToStr(idx)).arg(strValue) );
return strValue;
}
示例5: resolvedReplacement
static QString resolvedReplacement( const QString &replacement, const QRegExp &expr )
{
//qDebug("START");
static const QRegExp rexpr("(\\\\\\\\)|(\\\\[0-9]+)");
QString str( replacement );
int i=0;
while(i < str.size() && ((i = rexpr.indexIn(str, i)) != -1))
{
int len = rexpr.matchedLength();
if(rexpr.pos(1) != -1)
{
//qDebug("%i (%s): escape", i, CSTR(rexpr.cap(1)));
str.replace(i, len, "\\");
i += 1;
}
else if(rexpr.pos(2) != -1)
{
QString num_str = rexpr.cap(2);
num_str.remove(0, 1);
int num = num_str.toInt();
//qDebug("%i (%s): backref = %i", i, CSTR(rexpr.cap(2)), num);
if(num <= expr.captureCount())
{
QString cap = expr.cap(num);
//qDebug("resolving ref to: %s", CSTR(cap));
str.replace(i, len, cap);
i += cap.size();
}
else
{
//qDebug("ref out of range", i, num);
str.remove(i, len);
}
}
else
{
//qDebug("%i (%s): unknown match", i, CSTR(rexpr.cap(0)));
str.remove(i, len);
}
//qDebug(">> [%s] %i", CSTR(str), i);
}
//qDebug("END");
return str;
}
示例6: re
AstChanParts::AstChanParts(QString channel, QObject *parent)
:QObject(parent)
{
_isValid = false;
_prefix=QString();
_type=QString();
_exten=QString();
_extra=QString();
_special=QString();
QRegExp re ("^([^/]+/)?([^/]+)/([^-]+)([-])?([^<]+)?<?([^>]+)?>?$");
if(re.exactMatch(channel) && re.captureCount() == 6)
{
this->setPrefix(re.cap(1));
this->setType(re.cap(2));
this->setExten(re.cap(3));
this->setExtra(re.cap(5));
this->setSpecial(re.cap(6));
if(!_type.isNull() && !_type.isEmpty() && !_exten.isNull() && !_exten.isEmpty())
_isValid = true;
}
}
示例7: regexp
void Slog2InfoRunner::processLogLine(const QString &line)
{
// The "(\\s+\\S+)?" represents a named buffer. If message has noname (aka empty) buffer
// then the message might get cut for the first number in the message.
// The "\\s+(\\b.*)?$" represents a space followed by a message. We are unable to determinate
// how many spaces represent separators and how many are a part of the messages, so resulting
// messages has all whitespaces at the beginning of the message trimmed.
static QRegExp regexp(QLatin1String(
"^[a-zA-Z]+\\s+([0-9]+ [0-9]+:[0-9]+:[0-9]+.[0-9]+)\\s+(\\S+)(\\s+(\\S+))?\\s+([0-9]+)\\s+(.*)?$"));
if (!regexp.exactMatch(line) || regexp.captureCount() != 6)
return;
// Note: This is useless if/once slog2info -b displays only logs from recent launches
if (!m_launchDateTime.isNull()) {
// Check if logs are from the recent launch
if (!m_currentLogs) {
QDateTime dateTime = QDateTime::fromString(regexp.cap(1),
QLatin1String("dd HH:mm:ss.zzz"));
m_currentLogs = dateTime >= m_launchDateTime;
if (!m_currentLogs)
return;
}
}
QString applicationId = regexp.cap(2);
if (!applicationId.startsWith(m_applicationId))
return;
QString bufferName = regexp.cap(4);
int bufferId = regexp.cap(5).toInt();
// filtering out standard BB10 messages
if (bufferName == QLatin1String("default") && bufferId == 8900)
return;
emit output(regexp.cap(6).trimmed() + QLatin1Char('\n'), Utils::StdOutFormat);
}
示例8: extractResult
qint64 QBenchmarkValgrindUtils::extractResult(const QString &fileName)
{
QFile file(fileName);
const bool openOk = file.open(QIODevice::ReadOnly | QIODevice::Text);
Q_ASSERT(openOk);
Q_UNUSED(openOk);
qint64 val = -1;
bool valSeen = false;
const QRegExp rxValue(QLatin1String("^summary: (\\d+)"));
while (!file.atEnd()) {
const QString line(QLatin1String(file.readLine()));
if (rxValue.indexIn(line) != -1) {
Q_ASSERT(rxValue.captureCount() == 1);
bool ok;
val = rxValue.cap(1).toLongLong(&ok);
Q_ASSERT(ok);
valSeen = true;
break;
}
}
Q_ASSERT(valSeen);
return val;
}