コード例 #1
0
ファイル: Highlighter.cpp プロジェクト: lodacom/EditeurWeb
    foreach (const MultilineHighlightingRule &rule, multilineHighlightingRules)
    {
        QRegExp startExpression(rule.patternStart);
        QRegExp endExpression(rule.patternEnd);

        int startIndex = 0;
        if (previousBlockState() != rule.statusCode)
        {
            startIndex = startExpression.indexIn(text);
        }

        while (startIndex >= 0)
        {
            int endIndex = endExpression.indexIn(text, startIndex);
            int matchLength;

            if (endIndex == -1)
            {
                setCurrentBlockState(rule.statusCode);
                matchLength = text.length() - startIndex;
            }
            else
            {
                matchLength = endIndex - startIndex + endExpression.matchedLength();
            }

            setFormat(startIndex, matchLength, rule.format);
            startIndex = rule.patternStart.indexIn(text, startIndex + matchLength);
        }
    }
コード例 #2
0
ファイル: kccpphighlighter.cpp プロジェクト: Kreogist/Cuties
void KCCppHighlighter::conmmentHighlightBlock(const QString &text)
{
    QRegExp startExpression("/\\*");
    QRegExp endExpression("\\*/");
    KCTextBlockData *data=static_cast<KCTextBlockData *>(currentBlockUserData());

    setCurrentBlockState(0);

    int startIndex=0;
    if(previousBlockState() != 1)
    {
        startIndex=text.indexOf(startExpression);
    }

    bool searchNext;
    while(startIndex > -1)
    {
        searchNext=false;
        if(data->getLineCommentPos()>-1 &&
           startIndex > data->getLineCommentPos())
        {
            /*
             * Here means: begin char is no use!
             */
            startIndex=text.indexOf(startExpression, startIndex+1);
            continue;
        }
        for(auto i=data->getFirstQuotationInfo(),
            l=data->getEndQuotationInfo();
            i<l;
            i++)
        {
            if(startIndex > i->beginPos && startIndex < i->endPos)
            {
                startIndex=text.indexOf(startExpression, i->endPos+1);
                searchNext=true;
                break;
            }
        }
        if(searchNext)
        {
            continue;
        }
        int endIndex = text.indexOf(endExpression, startIndex);
        while(searchNext)
        {
            searchNext=false;
            for(auto i=data->getFirstQuotationInfo(),
                l=data->getEndQuotationInfo();
                i<l;
                i++)
            {
                if(endIndex > i->beginPos && endIndex < i->endPos)
                {
                    endIndex=text.indexOf(endExpression, i->endPos+1);
                    searchNext=true;
                    break;
                }
            }
        }
        int conmmentLength;
        if(endIndex == -1)
        {
            setCurrentBlockState(1);
            conmmentLength = text.length() - startIndex;
        }
        else
        {
            conmmentLength = endIndex - startIndex + endExpression.matchedLength();
        }
        setFormat(startIndex,conmmentLength,instance->getTextCharFormat("comment"));
        startIndex = text.indexOf(startExpression, startIndex+conmmentLength);
    }
}