本文整理汇总了C++中QRegularExpressionMatch::capturedEnd方法的典型用法代码示例。如果您正苦于以下问题:C++ QRegularExpressionMatch::capturedEnd方法的具体用法?C++ QRegularExpressionMatch::capturedEnd怎么用?C++ QRegularExpressionMatch::capturedEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRegularExpressionMatch
的用法示例。
在下文中一共展示了QRegularExpressionMatch::capturedEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: 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());
}
示例3: addBoldMarks
QString TxtFileView::addBoldMarks(QString txtline)
{
int i=0;
if(m_isRegEx) {
QRegularExpressionMatch match;
while( (match = m_stxtRe.match(txtline, i)).hasMatch() ) {
txtline.insert(match.capturedEnd(),"</u></b>");
txtline.insert(match.capturedStart(),"<b><u>");
i=match.capturedEnd()+6+8;
m_hits++;
}
}
else {
while ((i = txtline.indexOf(m_stxt, i, Qt::CaseInsensitive)) != -1) {
txtline.insert(i+m_stxt.size(),"</u></b>");
txtline.insert(i,"<b><u>");
i+=m_stxt.size()+6+8;
m_hits++;
}
}
return txtline;
}
示例4: filterAndAddToTextEdit
void AndroidDevice::filterAndAddToTextEdit(const QString& line)
{
static const QRegularExpression re(
"(?<date>[\\d-]+) *(?<time>[\\d:\\.]+) *(?<pid>\\d+) *(?<tid>\\d+) *(?<verbosity>[A-Z]) *(?<tag>.+):",
QRegularExpression::InvertedGreedinessOption | QRegularExpression::DotMatchesEverythingOption
);
bool filtersMatch = true;
const QRegularExpressionMatch match = re.match(line);
if (match.hasMatch())
{
const QStringRef date = match.capturedRef("date");
const QStringRef time = match.capturedRef("time");
const QStringRef pid = match.capturedRef("pid");
const QStringRef tid = match.capturedRef("tid");
const QStringRef verbosity = match.capturedRef("verbosity");
const QStringRef tag = match.capturedRef("tag").trimmed();
const QStringRef text = line.midRef(match.capturedEnd("tag") + 1);
const auto verbosityLevel = static_cast<VerbosityEnum>(Utils::verbosityCharacterToInt(verbosity.at(0).toLatin1()));
checkFilters(filtersMatch, m_filtersValid, verbosityLevel, pid, tid, tag, text);
if (filtersMatch)
{
const auto verbosityColorType = static_cast<ColorTheme::ColorType>(verbosityLevel);
m_deviceWidget->addText(verbosityColorType, verbosity);
m_deviceWidget->addText(ColorTheme::DateTime, date);
m_deviceWidget->addText(ColorTheme::DateTime, time);
m_deviceWidget->addText(ColorTheme::Pid, pid);
m_deviceWidget->addText(ColorTheme::Tid, tid);
m_deviceWidget->addText(ColorTheme::Tag, tag);
m_deviceWidget->addText(verbosityColorType, text);
m_deviceWidget->flushText();
}
}
else
{
qDebug() << "failed to parse" << line;
checkFilters(filtersMatch, m_filtersValid);
if (filtersMatch)
{
m_deviceWidget->addText(ColorTheme::VerbosityVerbose, QStringRef(&line));
m_deviceWidget->flushText();
}
}
m_deviceWidget->highlightFilterLineEdit(!m_filtersValid);
}
示例5: 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;
}
}
示例6: 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;
}
示例7: searchTxtLoop
bool SearchWorker::searchTxtLoop(QTextStream *intxt, QString searchtype, QString searchTerm, bool singleMatch, QString fullpath, QString displabel)
{
int matchcount=0;
QString matchline = "";
QString firstmatchline = "";
//prepare fo RegEx
bool enableRegEx = m_profile.getBoolOption(Profile::EnableRegEx);
const QRegularExpression searchExpr(searchTerm, QRegularExpression::UseUnicodePropertiesOption);
if(!searchExpr.isValid()) enableRegEx=false;
while (!intxt->atEnd()) {
if (m_cancelled.loadAcquire() == Cancelled)
return false;
QString linetxt = intxt->readLine();
int findpos=0;
QRegularExpressionMatch matchR;
//search for several occurences of search text in one line
while ( (findpos = (enableRegEx ? (matchR = searchExpr.match(linetxt, findpos)).capturedStart()
: linetxt.indexOf(searchTerm, findpos, Qt::CaseInsensitive))) != -1) {
//prepate line for output
if (findpos>10) matchline = "\u2026" + linetxt.mid(findpos-10,120);
else matchline = linetxt.left(120);
if(matchcount==0) firstmatchline=matchline;
enableRegEx ? findpos=matchR.capturedEnd() : findpos+=searchTerm.size();
matchcount++;
if(!singleMatch) {
//found result
//APPS only on single match
if(searchtype != "APPS") emit matchFound(fullpath, searchtype, displabel, matchline, 0);
}
if (m_cancelled.loadAcquire() == Cancelled)
return false;
}
}
if( singleMatch && (matchcount >0) ) {
//found result
if(searchtype == "APPS") {
displabel = prepareForApps(intxt);
matchcount = (-1)*matchcount;
if(displabel.size()>0)
emit matchFound(fullpath, searchtype, displabel, firstmatchline, matchcount);
}
else emit matchFound(fullpath, searchtype, displabel, firstmatchline, matchcount);
}
return true;
}
示例8: make_tuple
std::tuple<QString, QString> get_class_and_title(const QRegularExpressionMatch &match)
{
QString klass = match.captured(1).toLower();
QString title = match.captured(2);
if ( match.capturedEnd(2) == -1 ) {
//! no title was provided, use the capitalized classname as title
//! e.g.: `!!! note` will render
//! `<p class="admonition-title">Note</p>`
title = pypp::capitalize(klass);
} else if ( title.isEmpty() ) {
//! an explicit blank title should not be rendered
//! e.g.: `!!! warning ""` will *not* render `p` with a title
//title = QString();
}
return std::make_tuple(klass, title);
}
示例9: run
bool run(const markdown::Element &parent, QStringList &blocks)
{
QString block = blocks.first();
blocks.pop_front();
QRegularExpressionMatch m = this->RE.match(block);
if ( m.hasMatch() ) {
QString before = block.left(m.capturedStart()); // All lines before direction
QString after = block.mid(m.capturedEnd()); // All lines after direction
if ( ! before.isEmpty() ) {
// As the direction was not the first line of the block and the
// lines before the direction must be parsed first,
// recursively parse this lines as a block.
std::shared_ptr<markdown::BlockParser> parser = this->parser.lock();
QStringList new_blocks = {before};
parser->parseBlocks(parent, new_blocks);
}
// Create direction
QString body = m.captured(2);
// background-image
m = this->BGIMG_RE.match(body);
if ( m.hasMatch() ) {
markdown::Element img = markdown::createSubElement(parent, "img");
img->attrib["class"] = "background";
img->attrib["src"] = m.captured(1);
img->attrib["alt"] = m.captured(2);
}
// TODO: other direction
if ( ! m.hasMatch() ) {
markdown::Element p = markdown::createSubElement(parent, "p");
p->attrib["class"] = "comment";
p->text = body;
}
if ( ! after.isEmpty() ) {
// Insert remaining lines as first block for future parsing.
blocks.insert(0, after);
}
return true;
} else {
// This should never happen, but just in case...
qDebug() << "We've got a problem header: " << block;
return false;
}
}
示例10: run
bool run(const Element &parent, QStringList &blocks)
{
Element sibling = this->lastChild(parent);
QString block = blocks.front();
blocks.pop_front();
QRegularExpressionMatch m = this->RE.match(block);
if ( m.hasMatch() ) {
block = block.mid(m.capturedEnd()+1); //! removes the first line
}
QString theRest;
std::tie(block, theRest) = this->detab(block);
Element div;
if ( m.hasMatch() ) {
QString klass, title;
std::tie(klass, title) = this->get_class_and_title(m);
div = createSubElement(parent, "div");
div->set("class", QString("%1 %2").arg(this->classname()).arg(klass));
if ( ! title.isEmpty() ) {
Element p = createSubElement(div, "p");
p->text = title;
p->set("class", this->classname_title());
}
} else {
div = sibling;
}
std::shared_ptr<BlockParser> parser = this->parser.lock();
parser->parseChunk(div, block);
if ( ! theRest.isEmpty() ) {
//! This block contained unindented line(s) after the first indented
//! line. Insert these lines as the first block of the master blocks
//! list for future processing.
blocks.insert(0, theRest);
}
return true;
}
示例11: splitoutCellReference
QStringList WorkbookParserPrivate::splitoutCellReference(QString expression) {
QStringList result;
QRegularExpression re = QRegularExpression(REGEX_CELL_REFERENCE_2);
QRegularExpressionMatch match;
int start, end = 0;
QRegularExpressionMatchIterator it = re.globalMatch(expression);
while (it.hasNext()) {
match = it.next();
start = match.capturedStart(0);
result.append(expression.mid(end, start - end));
// TODO replace cell references with actual contents of cell
result.append(match.captured(0));
// TODO above
end = match.capturedEnd(0);
}
if (end < expression.length())
result.append(expression.mid(end));
return result;
}
示例12: parseLinks
void FlatTextarea::parseLinks() { // some code is duplicated in text.cpp!
LinkRanges newLinks;
QString text(toPlainText());
if (text.isEmpty()) {
if (!_links.isEmpty()) {
_links.clear();
emit linksChanged();
}
return;
}
initLinkSets();
int32 len = text.size();
const QChar *start = text.unicode(), *end = start + text.size();
for (int32 offset = 0, matchOffset = offset; offset < len;) {
QRegularExpressionMatch m = reDomain().match(text, matchOffset);
if (!m.hasMatch()) break;
int32 domainOffset = m.capturedStart();
QString protocol = m.captured(1).toLower();
QString topDomain = m.captured(3).toLower();
bool isProtocolValid = protocol.isEmpty() || validProtocols().contains(hashCrc32(protocol.constData(), protocol.size() * sizeof(QChar)));
bool isTopDomainValid = !protocol.isEmpty() || validTopDomains().contains(hashCrc32(topDomain.constData(), topDomain.size() * sizeof(QChar)));
if (protocol.isEmpty() && domainOffset > offset + 1 && *(start + domainOffset - 1) == QChar('@')) {
QString forMailName = text.mid(offset, domainOffset - offset - 1);
QRegularExpressionMatch mMailName = reMailName().match(forMailName);
if (mMailName.hasMatch()) {
offset = matchOffset = m.capturedEnd();
continue;
}
}
if (!isProtocolValid || !isTopDomainValid) {
offset = matchOffset = m.capturedEnd();
continue;
}
QStack<const QChar*> parenth;
const QChar *domainEnd = start + m.capturedEnd(), *p = domainEnd;
for (; p < end; ++p) {
QChar ch(*p);
if (chIsLinkEnd(ch)) break; // link finished
if (chIsAlmostLinkEnd(ch)) {
const QChar *endTest = p + 1;
while (endTest < end && chIsAlmostLinkEnd(*endTest)) {
++endTest;
}
if (endTest >= end || chIsLinkEnd(*endTest)) {
break; // link finished at p
}
p = endTest;
ch = *p;
}
if (ch == '(' || ch == '[' || ch == '{' || ch == '<') {
parenth.push(p);
} else if (ch == ')' || ch == ']' || ch == '}' || ch == '>') {
if (parenth.isEmpty()) break;
const QChar *q = parenth.pop(), open(*q);
if ((ch == ')' && open != '(') || (ch == ']' && open != '[') || (ch == '}' && open != '{') || (ch == '>' && open != '<')) {
p = q;
break;
}
}
}
if (p > domainEnd) { // check, that domain ended
if (domainEnd->unicode() != '/' && domainEnd->unicode() != '?') {
matchOffset = domainEnd - start;
continue;
}
}
newLinks.push_back(qMakePair(domainOffset - 1, p - start - domainOffset + 2));
offset = matchOffset = p - start;
}
if (newLinks != _links) {
_links = newLinks;
emit linksChanged();
}
}
示例13: loadSfz
bool ZInstrument::loadSfz(const QString& s)
{
_program = 0;
QFile f(s);
if (!f.open(QIODevice::ReadOnly)) {
qDebug("ZInstrument: cannot load %s", qPrintable(s));
return false;
}
QFileInfo fi(f);
QString path = fi.absolutePath();
qint64 total = fi.size();
QString sample;
SfzRegion r;
SfzRegion g; // group
r.init(path);
g.init(path);
bool groupMode = false;
zerberus->setLoadProgress(0);
while (!f.atEnd()) {
QByteArray ba = f.readLine();
zerberus->setLoadProgress(((qreal)f.pos() * 100) / total);
ba = ba.simplified();
if (ba.isEmpty() || ba.startsWith("//"))
continue;
if (zerberus->loadWasCanceled())
return false;
if (ba.startsWith("<group>")) {
if (!groupMode && !r.isEmpty())
addRegion(r);
g.init(path);
r.init(path);
groupMode = true;
ba = ba.mid(7);
}
else if (ba.startsWith("<region>")) {
if (groupMode) {
g = r;
groupMode = false;
}
else {
if (!r.isEmpty())
addRegion(r);
r = g; // initialize next region with group values
}
ba = ba.mid(8);
}
QRegularExpression re("\\s?(\\w+)=");
QRegularExpressionMatchIterator i = re.globalMatch(ba);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
int si = match.capturedEnd();
int ei;
if (i.hasNext()) {
QRegularExpressionMatch nextMatch = i.peekNext();
ei = nextMatch.capturedStart();
}
else
ei = ba.size();
QString s = ba.mid(si, ei-si);
r.readOp(match.captured(1), s);
}
}
zerberus->setLoadProgress(100);
if (!groupMode && !r.isEmpty())
addRegion(r);
return true;
}
示例14: parseData
void SourceEntryPrivate::parseData(const QString &data)
{
if (data.isEmpty())
return;
QString tData = data.simplified();
// Check for nonvalid input
if (tData.isEmpty() || tData == QChar('#')) {
isValid = false;
return;
}
// Check source enable state
if (tData.at(0) == '#') {
isEnabled = false;
}
// Handle multiple comment characters (hey, it happens!)
while (tData.size() > 0 && tData.at(0) == '#') {
// Remove starting '#' from tData
tData = tData.remove(0, 1);
tData = tData.trimmed();
}
// Find any #'s past the start (these are comments)
int idx = tData.indexOf('#');
if (idx > 0) {
// Save the comment, then remove from tData
comment = tData.right(tData.size() - idx - 1);
tData.remove(idx, tData.size() - idx + 1);
}
const QRegularExpression rx("^([a-z\\-]+) *");
QRegularExpressionMatch match = rx.match(tData);
// Parse type
type = match.captured(1);
const QSet<QString> types = { QLatin1String("rpm"), QLatin1String("rpm-src"), QLatin1String("deb"), QLatin1String("deb-src") };
if (!match.isValid() || !types.contains(type)) {
isValid = false;
return;
}
int start = match.capturedEnd(), end = tData.size();
// Parse architecture, see https://wiki.debian.org/Multiarch/HOWTO, Setting up sources
if (tData[start] == '[') {
QString metadata = tData.mid(start+1, tData.indexOf(']')-start-1);
QStringList options = metadata.split(';');
for (const QString &option : options) {
QStringList parts = option.split('=');
if (parts.size() != 2) {
isValid = false;
return;
}
QString key = parts.at(0);
if (key != QLatin1String("arch")) {
isValid = false;
return;
}
QString value = parts.at(1);
architectures = value.split(',');
}
start+=metadata.size()+2;
for (; tData[start] == ' '; ++start)
{}
}
bool inString = false;
bool done = false;
for (int i = start; !done && i<end; ++i) {
switch (tData[i].toLatin1()) {
case ' ':
if (!inString) {
uri = tData.mid(start, i-start);
start = i+1;
done = true;
} break;
case '[':
inString = true;
break;
case ']':
inString = false;
break;
}
}
if (uri.isEmpty() || !done) {
isValid = false;
return;
}
QStringList pieces = tData.mid(start).split(' ', QString::SkipEmptyParts);
if (pieces.isEmpty()) {
// Invalid source entry
isValid = false;
return;
}
//.........这里部分代码省略.........
示例15: search
QList<HTMLSpellCheck::MisspelledWord> HTMLSpellCheck::GetMisspelledWords(const QString &orig_text,
int start_offset,
int end_offset,
const QString &search_regex,
bool first_only,
bool include_all_words)
{
SpellCheck *sc = SpellCheck::instance();
QString wordChars = sc->getWordChars();
bool in_tag = false;
bool in_invalid_word = false;
bool in_entity = false;
int word_start = 0;
QRegularExpression search(search_regex);
QList<HTMLSpellCheck::MisspelledWord> misspellings;
// Make sure text has beginning/end boundary markers for easier parsing
QString text = QChar(' ') + orig_text + QChar(' ');
// Ignore <style...</style> wherever it appears - change to spaces to keep text positions
QRegularExpression style_re("<style[^<]*</style>");
QRegularExpressionMatchIterator i = style_re.globalMatch(text);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
for (int pos = match.capturedStart(); pos < match.capturedEnd(); pos++) {
text[pos] = QChar(' ');
}
}
for (int i = 0; i < text.count(); i++) {
QChar c = text.at(i);
if (!in_tag) {
QChar prev_c = i > 0 ? text.at(i - 1) : QChar(' ');
QChar next_c = i < text.count() - 1 ? text.at(i + 1) : QChar(' ');
if (IsBoundary(prev_c, c, next_c, wordChars)) {
// If we're in an entity and we hit a boundary and it isn't
// part of an entity then this is an invalid entity.
if (in_entity && c != QChar(';')) {
in_entity = false;
}
// Check possibilities that would mean this isn't a word worth considering.
if (!in_invalid_word && !in_entity && word_start != -1 && (i - word_start) > 0) {
QString word = Utility::Substring(word_start, i, text);
if (!word.isEmpty() && word_start > start_offset && word_start <= end_offset) {
if (include_all_words || !sc->spell(word)) {
int cap_start = -1;
if (!search_regex.isEmpty()) {
QRegularExpressionMatch mo = search.match(word);
cap_start = mo.capturedStart();
}
if (search_regex.isEmpty() || cap_start != -1) {
struct MisspelledWord misspelled_word;
misspelled_word.text = word;
// Make sure we account for the extra boundary added at the beginning
misspelled_word.offset = word_start - 1;
misspelled_word.length = i - word_start ;
misspellings.append(misspelled_word);
if (first_only) {
return misspellings;
}
}
}
}
}
// We want to start the word with the character after the boundary.
// If the next character is another boundary we'll just move forward one.
word_start = i + 1;
in_invalid_word = false;
} else {
// Ensure we're not dealing with some crazy run on text that isn't worth
// considering as an actual word.
if (!in_invalid_word && (i - word_start) > MAX_WORD_LENGTH) {
in_invalid_word = true;
}
}
if (c == QChar('&')) {
in_entity = true;
}
if (c == QChar(';')) {
in_entity = false;
}
}
if (c == QChar('<')) {
in_tag = true;
word_start = -1;
}
if (in_tag && c == QChar('>')) {
word_start = i + 1;
in_tag = false;
//.........这里部分代码省略.........