コード例 #1
0
QList<LocatorFilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future,
                                                          const QString &entry)
{
    QList<LocatorFilterEntry> goodEntries;
    QList<LocatorFilterEntry> betterEntries;
    const EditorManager::FilePathInfo fp = EditorManager::splitLineAndColumnNumber(entry);

    const QRegularExpression regexp = createRegExp(fp.filePath);
    if (!regexp.isValid())
        return goodEntries;

    const QList<Entry> editorEntries = editors();
    for (const Entry &editorEntry : editorEntries) {
        if (future.isCanceled())
            break;
        QString fileName = editorEntry.fileName.toString();
        if (fileName.isEmpty())
            continue;
        QString displayName = editorEntry.displayName;
        const QRegularExpressionMatch match = regexp.match(displayName);
        if (match.hasMatch()) {
            LocatorFilterEntry filterEntry(this, displayName, QString(fileName + fp.postfix));
            filterEntry.extraInfo = FileUtils::shortNativePath(FileName::fromString(fileName));
            filterEntry.fileName = fileName;
            filterEntry.highlightInfo = highlightInfo(match);
            if (match.capturedStart() == 0)
                betterEntries.append(filterEntry);
            else
                goodEntries.append(filterEntry);
        }
    }
    betterEntries.append(goodEntries);
    return betterEntries;
}
コード例 #2
0
static FontKeys &fontKeys()
{
    static FontKeys result;
    if (result.isEmpty()) {
        const QSettings fontRegistry(QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"),
                                     QSettings::NativeFormat);
        const QStringList allKeys = fontRegistry.allKeys();
        const QString trueType = QStringLiteral("(TrueType)");
        const QRegularExpression sizeListMatch(QStringLiteral("\\s(\\d+,)+\\d+"));
        Q_ASSERT(sizeListMatch.isValid());
        const int size = allKeys.size();
        result.reserve(size);
        for (int i = 0; i < size; ++i) {
            FontKey fontKey;
            const QString &registryFontKey = allKeys.at(i);
            fontKey.fileName = fontRegistry.value(registryFontKey).toString();
            QString realKey = registryFontKey;
            realKey.remove(trueType);
            realKey.remove(sizeListMatch);
            const QStringList fontNames = realKey.trimmed().split(QLatin1Char('&'));
            fontKey.fontNames.reserve(fontNames.size());
            foreach (const QString &fontName, fontNames)
                fontKey.fontNames.append(fontName.trimmed());
            result.append(fontKey);
        }
    }
    return result;
}
コード例 #3
0
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();
}
コード例 #4
0
ファイル: Ratings.cpp プロジェクト: bubble501/CLOModel
bool Ratings::setRating(const QString& val, RatingAgency ag)
{
    qint32 agencyIndex;

    for (agencyIndex = 0;; ++agencyIndex) {
        Q_ASSERT(agencyIndex <= CountRatingAcencies);
        if (static_cast<qint32>(ag) == (1 << agencyIndex))
            break;
    }
    /////////////////Fix for bloomberg return values in excel//////////////////
    if (val.trimmed().toUpper().left(4) == "#N/A") {
        setRating(RatingValue::NR, ag);
        setWatch(Stable, ag);
        return true;
    }
    //////////////////////////////////////////////////////////////////////////
    const  auto agencySyntax = RatingsPrivate::m_ratingSyntax[agencyIndex];
    QRegularExpression syntaxCheck;
    syntaxCheck.setPatternOptions(QRegularExpression::CaseInsensitiveOption | QRegularExpression::DontCaptureOption);
    for (int i = static_cast<qint16>(RatingValue::AAA); i <= static_cast<qint16>(RatingValue::Dm); ++i){
        if (!agencySyntax[i].isEmpty()) {
            syntaxCheck.setPattern(
                "(^|[^" + QRegularExpression::escape(RatingsPrivate::m_reservedChars[agencyIndex]) + "])"
                + QRegularExpression::escape(agencySyntax[i])
                + "($|[^" + QRegularExpression::escape(RatingsPrivate::m_reservedChars[agencyIndex]) + "])"
                );
            Q_ASSERT(syntaxCheck.isValid());
            if (syntaxCheck.match(val).hasMatch()){
                    setRating(static_cast<RatingValue>(i), ag);
                    break;
            }
        }
        if (i == static_cast<qint16>(RatingValue::Dm)) {
            setRating(RatingValue::NR, ag, Stable);
            return false;
        }
    }
    if (val.indexOf("*-", 0, Qt::CaseInsensitive) >= 0)
        setWatch(Negative, ag);
    else if (val.indexOf("*+", 0, Qt::CaseInsensitive) >= 0)
        setWatch(Positive, ag);
    else
        setWatch(Stable, ag);
    return true;
}
コード例 #5
0
ファイル: Filters.cpp プロジェクト: AutoRunWare/Ultracopier
bool Filters::convertToRegex(Filters_rules &item)
{
    bool isValid=!item.search_text.isEmpty();
    if(isValid)
    {
        QRegularExpression regex;
        QString tempString;
        if(item.search_type==SearchType_rawText)
        {
            tempString=QRegularExpression::escape(item.search_text);
            if(tempString.contains('/') || tempString.contains('\\'))
                isValid=false;
        }
        else if(item.search_type==SearchType_simpleRegex)
        {
            tempString=QRegularExpression::escape(item.search_text);
            tempString.replace("\\*","[^\\\\/]*");
        }
        else if(item.search_type==SearchType_perlRegex)
        {
            tempString=item.search_text;
            if(tempString.startsWith('^') && tempString.endsWith('$'))
            {
                item.need_match_all=true;
                tempString.remove(QRegularExpression("^\\^"));
                tempString.remove(QRegularExpression("\\$$"));
                item.search_text=tempString;
            }
        }
        if(isValid)
        {
            if(item.need_match_all==true)
                tempString="^"+tempString+"$";
            regex=QRegularExpression(tempString);
            isValid=regex.isValid();
            item.regex=regex;
            return true;
        }
        else
            return false;
    }
    return false;
}
コード例 #6
0
bool syntax_highlighter::IsInvalidExpression(const QRegularExpression& expression)
{
	return !expression.isValid() || expression.pattern().isEmpty();
}
コード例 #7
0
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;
        }
    }
}
コード例 #8
0
void ProjectIntroPage::setProjectNameRegularExpression(const QRegularExpression &regEx)
{
    Q_ASSERT_X(regEx.isValid(), Q_FUNC_INFO, qPrintable(regEx.errorString()));
    d->m_projectNameValidator.setRegularExpression(regEx);
}
コード例 #9
0
ファイル: filepattern.cpp プロジェクト: mjmvisser/pug
const QString FilePattern::patternFromPath(const QString &path)
{
    if (path.isEmpty())
        return QString();

    static const QRegularExpression MATCH_FILENAME_WITH_FRAME(
            "^"
            "(?<directory>(.*/)?)"
            "(?<baseName>[^.]*)"
            "([.]"
                "("
                    "(?<frame>[0-9.]*?)|"
                    "(?<frameSpec>"
                        "(?<hash>#+)|"
                        "(?<whirl>@+)|"
                        "(?<nuke>%0\\d+d)|"
                        "(?<houdini>($F?<width>(\\d?)))"
                    ")"
                ")"
            ")?"
            "([.]"
                "(?<extension>[^.]*)"
            ")?"
            "$");

    Q_ASSERT(MATCH_FILENAME_WITH_FRAME.isValid());

    QRegularExpressionMatch match = MATCH_FILENAME_WITH_FRAME.match(path);
    if (match.hasMatch()) {
        const QString directory = match.captured("directory");

        const QString baseName = match.captured("baseName");

        QString frameSpec;
        if (!match.captured("frame").isNull()) {
            int width = match.captured("frame").length();
            if (width >= 3 || (width >=1 && match.captured("frame").at(0) == '0')) {
                frameSpec = "%" + QString("0%1d").arg(width);
            } else {
                frameSpec = "%d";
            }
        } else if (!match.captured("hash").isNull()) {
            int width = match.captured("hash").length();
            if (width == 1)
                width = 4;
            frameSpec = "%" + QString("0%1d").arg(width);

        } else if (!match.captured("whirl").isNull()) {
            int width = match.captured("whirl").length();
            frameSpec = "%" + QString("0%1d").arg(width);

        } else if (!match.captured("nuke").isNull()) {
            frameSpec = match.captured("nuke");

        } else if (!match.captured("houdini").isNull()) {
            bool ok;
            int width = match.captured("width").toFloat(&ok);
            if (ok) {
                frameSpec = "%" + QString("0%1d").arg(width);
            }
        }

        const QString extension = match.captured("extension");

        QString pattern;

        if (!directory.isNull())
            pattern += directory;
        if (!baseName.isNull())
            pattern += baseName;
        if (!frameSpec.isNull())
            pattern += "." + frameSpec;
        if (!extension.isNull())
            pattern += "." + extension;

        return pattern;

    } else {
        qWarning() << "couldn't match path" << path;
        return QString();
    }
}