本文整理汇总了C++中QRegularExpressionMatch::hasPartialMatch方法的典型用法代码示例。如果您正苦于以下问题:C++ QRegularExpressionMatch::hasPartialMatch方法的具体用法?C++ QRegularExpressionMatch::hasPartialMatch怎么用?C++ QRegularExpressionMatch::hasPartialMatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRegularExpressionMatch
的用法示例。
在下文中一共展示了QRegularExpressionMatch::hasPartialMatch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validate
QValidator::State QRegularExpressionValidator::validate(QString &input, int &pos) const
{
Q_D(const QRegularExpressionValidator);
// We want a validator with an empty QRegularExpression to match anything;
// since we're going to do an exact match (by using d->usedRe), first check if the rx is empty
// (and, if so, accept the input).
if (d->origRe.pattern().isEmpty())
return Acceptable;
const QRegularExpressionMatch m = d->usedRe.match(input, 0, QRegularExpression::PartialPreferCompleteMatch);
if (m.hasMatch()) {
return Acceptable;
} else if (m.hasPartialMatch()) {
return Intermediate;
} else {
pos = input.size();
return Invalid;
}
}
示例2: main
//.........这里部分代码省略.........
if (match.hasMatch()) {
QString date = match.captured("date"); // date == "08"
QString month = match.captured("month"); // month == "12"
QString year = match.captured("year"); // year == 1985
}
//! [12]
}
{
//! [13]
QRegularExpression re("(\\w+)");
QRegularExpressionMatchIterator i = re.globalMatch("the quick fox");
//! [13]
//! [14]
QStringList words;
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
QString word = match.captured(1);
words << word;
}
// words contains "the", "quick", "fox"
//! [14]
}
{
//! [15]
QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$");
QRegularExpression re(pattern);
QString input("Jan 21,");
QRegularExpressionMatch match = re.match(input, 0, QRegularExpression::PartialPreferCompleteMatch);
bool hasMatch = match.hasMatch(); // false
bool hasPartialMatch = match.hasPartialMatch(); // true
//! [15]
}
{
QString pattern("^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d\\d?, \\d\\d\\d\\d$");
QRegularExpression re(pattern);
//! [16]
QString input("Dec 8, 1985");
QRegularExpressionMatch match = re.match(input, 0, QRegularExpression::PartialPreferCompleteMatch);
bool hasMatch = match.hasMatch(); // true
bool hasPartialMatch = match.hasPartialMatch(); // false
//! [16]
}
{
//! [17]
QRegularExpression re("abc\\w+X|def");
QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpression::PartialPreferCompleteMatch);
bool hasMatch = match.hasMatch(); // true
bool hasPartialMatch = match.hasPartialMatch(); // false
QString captured = match.captured(0); // captured == "def"
//! [17]
}
{
//! [18]
QRegularExpression re("abc\\w+X|defY");
QRegularExpressionMatch match = re.match("abcdef", 0, QRegularExpression::PartialPreferCompleteMatch);
bool hasMatch = match.hasMatch(); // false
bool hasPartialMatch = match.hasPartialMatch(); // true
QString captured = match.captured(0); // captured == "abcdef"
//! [18]
示例3: 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;
};