Menu

#1374 Thread search: New Search option "Exclude comments"

Undefined
open
nobody
Feature_Request
2023-12-18
2023-02-05
Tiger Beard
No

Thead search today has the following options
Whole word
Start word
Match case
Regular Expression

I propose to add th option
Exclude comments

It would not list lines matching the format
<whitespace>//<anything></anything></whitespace>

Reason
CB already has the very powerful Ctrl-Shift-C, Ctrl-Shift-X feature to add or remove "//" to a block of code. I am using this very often during debug and test.
The search list is often flooded with commented-out sections. Sometimes its desired, but often its not. Using that option would allow to take out a lot of noise from the list (at least for people using comments ;-).

Disadvantages
obviously there is potential confusion since
* it only works on C++ style single line comments "//". It would not remove /* as multiline logic is probably overkill.
* there are no "//" in C, so for pure C programs that option would be not useful
* I do not know Fortran, but might be the same
I think the same disadvantages apply to the Ctrl-Shift-C, Ctrl-Shift-X feature, so it would be consistent
to add this to thread search despite these disadvantages. The gain imho would outweight those.

Discussion

  • ollydbg

    ollydbg - 2023-03-27

    I take some time to read the source code of this plugin. I think if you want that option, you need to change this function:

        /** Return true if line matches search text.
          * This method must be implemented in derived classes to allows using
          * different search strategies (at least simple text and regular expressions).
          * @param line : the text line to match.
          * @return true if line matches search text.
          */
        virtual bool MatchLine(std::vector<int> *outMatchedPositions, const wxString &line) = 0;
    
    You can see there is a function named:
    
        bool TextFileSearcherText::MatchLine(std::vector<int> *outMatchedPositions,
                                         const wxString &originalLine)
    {
        wxString line;
        if ( m_MatchCase == false )
        {
            line = originalLine.Lower();
        }
        else
        {
            line = originalLine;
        }
    
        wxString::size_type start = 0;
        int count = 0;
    
        const std::vector<int>::size_type countIdx = outMatchedPositions->size();
    
        do
        {
            // "TestTest Test"
            // start word [0;4], [9;4]
            // match word [9;4]
            // none [0;4] [4;4] [9;4]
    
            wxString::size_type pos = line.find(m_SearchText, start);
            if (pos == wxString::npos)
                break;
    
            if ((m_MatchWordBegin || m_MatchWord) && pos > 0)
            {
                // Try to see if this is the start of the word.
                const wxUniChar prevChar = line.GetChar(pos - 1);
                if (wxIsalnum(prevChar) || prevChar == '_')
                {
                    start++;
                    continue;
                }
            }
    
            if (m_MatchWord && (pos + m_SearchText.length() < line.length()))
            {
                // Try to see if this is the end of the word.
                const wxUniChar nextChar = line.GetChar(pos + m_SearchText.length());
                if (wxIsalnum(nextChar) || nextChar == '_')
                {
                    start++;
                    continue;
                }
            }
    
            // We have a match add positions for it.
            if (count == 0)
                outMatchedPositions->push_back(0);
            ++count;
            outMatchedPositions->push_back(pos);
            outMatchedPositions->push_back(m_SearchText.length());
    
            start = pos + m_SearchText.length();
        } while (1);
    
        if (count > 0)
        {
            (*outMatchedPositions)[countIdx] = count;
            return true;
        }
        else
            return false;
    }
    

    So, I think you can modify this function to skip the lines if it start with "//".

    Can you try it yourself?

     

    Last edit: ollydbg 2023-03-27
  • Tiger Beard

    Tiger Beard - 2023-03-27

    Thanks for the hints and your time. I see what I can do.

     
  • Tiger Beard

    Tiger Beard - 2023-12-18

    Took quite a while but now i managed to get a working compile environment and implemented the proposal.
    See patch #1436

    The patch adds the option "Match In Comments". Its checked by default because then the behaviour is the same as today. It only works with C++ style comments "//" both full line and end of line. This info was put into the tooltip string.
    Tested in Linux 22.04 with wxWidgets3.0.5 only.

    i hope you find it a useful addition.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.