/*void RegExpFilter::reset(int)
{
    _buffer = QString();
}*/
void RegExpFilter::process()
{
    int pos = 0;
    const QString* text = buffer();

    Q_ASSERT( text );

    // ignore any regular expressions which match an empty string.
    // otherwise the while loop below will run indefinitely
    static const QString emptyString("");
    if ( _searchText.exactMatch(emptyString) )
        return;

    while(pos >= 0)
    {
        pos = _searchText.indexIn(*text,pos);

        if ( pos >= 0 )
        {
            int startLine = 0;
            int endLine = 0;
            int startColumn = 0;
            int endColumn = 0;

            getLineColumn(pos,startLine,startColumn);
            getLineColumn(pos + _searchText.matchedLength(),endLine,endColumn);

            RegExpFilter::HotSpot* spot = newHotSpot(startLine,startColumn,
                                           endLine,endColumn);
            spot->setCapturedTexts(_searchText.capturedTexts());

            addHotSpot( spot );
            pos += _searchText.matchedLength();

            // if matchedLength == 0, the program will get stuck in an infinite loop
            if ( _searchText.matchedLength() == 0 )
                pos = -1;
        }
    }
}
Example #2
0
OovStringVec Tokenizer::codeComplete(size_t offset)
    {
    CLangAutoLock lock(mCLangLock, __LINE__, this);
    OovStringVec strs;
    unsigned options = 0;
// This gets more than we want.
//    unsigned options = clang_defaultCodeCompleteOptions();
    unsigned int line;
    unsigned int column;
    getLineColumn(offset, line, column);
    CXCodeCompleteResults *results = clang_codeCompleteAt(mTransUnit,
            mSourceFilename.getStr(), line, column,
            nullptr, 0, options);
    if(results)
        {
        clang_sortCodeCompletionResults(&results->Results[0], results->NumResults);
        for(size_t ri=0; ri<results->NumResults /*&& ri < 50*/; ri++)
            {
            OovString str;
            CXCompletionString compStr = results->Results[ri].CompletionString;
            size_t numChunks = clang_getNumCompletionChunks(compStr);
            for(size_t ci=0; ci<numChunks && ci < 30; ci++)
                {
                CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(compStr, ci);
                // We will discard return values from functions, so the first
                // chunk returned will be the identifier or function name.  Function
                // arguments will be returned after a space, so they can be
                // discarded easily.
                if(chunkKind == CXCompletionChunk_TypedText || str.length())
                    {
                    std::string chunkStr = getDisposedString(clang_getCompletionChunkText(compStr, ci));
                    if(str.length() != 0)
                    str += ' ';
                    str += chunkStr;
                    }
                }
            strs.push_back(str);
            }
        clang_disposeCodeCompleteResults(results);
        }
    return strs;
    }