Beispiel #1
0
/*!
    \internal

    Sets \a re as the regular expression. It wraps the regexp that's actually used
    between \\A and \\z, therefore forcing an exact match.
*/
void QRegularExpressionValidatorPrivate::setRegularExpression(const QRegularExpression &re)
{
    Q_Q(QRegularExpressionValidator);

    if (origRe != re) {
        usedRe = origRe = re; // copies also the pattern options
        usedRe.setPattern(QStringLiteral("\\A(?:") + re.pattern() + QStringLiteral(")\\z"));
        emit q->regularExpressionChanged(re);
        emit q->changed();
    }
}
void MultipleFilterProxy::setRegExpFilter(qint32 col, const QRegularExpression& matcher, qint32 role, bool match)
{
    if (col < 0 || col >= m_dateRangeFilter.size())
        return;
    if (matcher.pattern().isEmpty() || !matcher.isValid())
        return removeFilterFromColumn(col, role);
    m_dateRangeFilter[col].remove(role);
    m_boolFilter[col].remove(role);
    m_regExpFilter[col][role] = std::make_pair(matcher, match);
    invalidateFilter();
}
Beispiel #3
0
/*!
    \fn int QStringList::indexOf(const QRegularExpression &re, int from) const
    \overload
    \since 5.0

    Returns the index position of the first match of \a re in
    the list, searching forward from index position \a from. Returns
    -1 if no item matched.

    \sa lastIndexOf()
*/
int QtPrivate::QStringList_indexOf(const QStringList *that, const QRegularExpression &re, int from)
{
    if (from < 0)
        from = qMax(from + that->size(), 0);

    QString exactPattern = QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z");
    QRegularExpression exactRe(exactPattern, re.patternOptions());

    for (int i = from; i < that->size(); ++i) {
        QRegularExpressionMatch m = exactRe.match(that->at(i));
        if (m.hasMatch())
            return i;
    }
    return -1;
}
bool syntax_highlighter::IsInvalidExpression(const QRegularExpression& expression)
{
	return !expression.isValid() || expression.pattern().isEmpty();
}
void MarkupHighlighter::highlightBlock(const QString &text)
{

    if (FORMATTING.empty()){
        qWarning() << "Not given any formatting, so not highlighting.";
        return;
    }

    if (text.isEmpty()) return;

    int start=0, end=0, highlightLength = 0;

    QRegularExpression re;
    QTextCharFormat textFormat;
    for (QString exp : TOKENS.keys()){
        setCurrentBlockState(0);
        start = 0, end = 0;

        re = QRegularExpression(exp);

        if (!re.isValid()){
            QString message = "Invalid regular expression \""
                    + re.pattern() + "\" :" + re.errorString();
            qFatal("%s", message.toStdString().data());
            return;
        }

        if (previousBlockState() != 1)
            start = re.match(text).capturedStart();

        while (start >= 0){
            QRegularExpressionMatch match = re.match(text, start);
            end = match.capturedEnd();
            if (end == -1 || (end == start && end != 0)){
                setCurrentBlockState(1);
                highlightLength = text.length();
            } else {
                highlightLength = match.capturedLength();
            }
            QTextCharFormat baseFormat = currentBlock().blockFormat().toCharFormat();
            MarkupHighlighter::MarkupToken tok = TOKENS[exp];
            if (!FORMATTING.contains(tok)){
                qWarning() << "Could not find" << tok;
                break;
            }
            const StyleProxy *styleProxy = FORMATTING[tok];
            textFormat = styleProxy->toFormat(baseFormat);
            setFormat(start, highlightLength, textFormat);
            qDebug() << "highlightBlock";
            qDebug() << "Formatting"
                     << "token" << tok
                     << "with regex=" << exp
                     << ", string="
                     << text.mid(start, highlightLength)
                     << "\n"
                     << "  Bold?" << textFormat.font().bold() << "\n"
                     << "  Italic?" << textFormat.font().italic() << "\n"
                     << "  Size:" << textFormat.font().pointSize() << "\n"
                     << "  Background:" << textFormat.background().color();
            start = re.match(text, end).capturedStart();
            // This should not be 0 again. If it is, that means our search has
            // come up empty.
            if (start == 0)
                start = -1;
        }
    }
}