~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/ThreadSearch/TextFileSearcherText.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************
 
2
 * Name:      TextFileSearcherText
 
3
 * Purpose:   TextFileSearcherText is used to search text files
 
4
 *            for text pattern.
 
5
 * Author:    Jerome ANTOINE
 
6
 * Created:   2007-04-07
 
7
 * Copyright: Jerome ANTOINE
 
8
 * License:   GPL
 
9
 **************************************************************/
 
10
 
 
11
#include "TextFileSearcherText.h"
 
12
 
 
13
 
 
14
TextFileSearcherText::TextFileSearcherText(const wxString& searchText, bool matchCase, bool matchWordBegin,
 
15
                                           bool matchWord)
 
16
                     :TextFileSearcher(searchText, matchCase, matchWordBegin, matchWord)
 
17
{
 
18
    if ( matchCase == false )
 
19
    {
 
20
        m_SearchText.LowerCase();
 
21
    }
 
22
}
 
23
 
 
24
 
 
25
bool TextFileSearcherText::MatchLine(wxString line)
 
26
{
 
27
    bool match = false;
 
28
    if ( m_MatchCase == false )
 
29
    {
 
30
        line.LowerCase();
 
31
    }
 
32
    int pos = line.Find(m_SearchText.c_str());
 
33
    int nextPos;
 
34
    while ( (match == false) && (pos >= 0) )
 
35
    {
 
36
        char c = ' '; // c is either the preceeding char or a virtual char
 
37
                      // that matches systematically the required conditions
 
38
        match = true; // pos > 0 => expr found => Matches. Let's test start word
 
39
                      // and whole words conditions.
 
40
        if ( (m_MatchWordBegin == true) || (m_MatchWord == true) )
 
41
        {
 
42
            if ( pos > 0 )
 
43
            {
 
44
                c = line.GetChar(pos - 1);
 
45
            }
 
46
            //match = (__iscsym(c) == 0);
 
47
            match = !(isalnum(c) || ( c == '_' ));
 
48
        }
 
49
 
 
50
        if ( (match == true) && (m_MatchWord == true) )
 
51
        {
 
52
            c = ' ';
 
53
            if ( (pos + m_SearchText.Length()) < line.Length() )
 
54
            {
 
55
                c = line.GetChar(pos + m_SearchText.Length());
 
56
            }
 
57
            match = !(isalnum(c) || ( c == '_' ));
 
58
        }
 
59
 
 
60
        nextPos = line.Mid(pos+1).Find(m_SearchText.c_str());
 
61
        if ( nextPos >= 0 )
 
62
        {
 
63
            pos += nextPos + 1;
 
64
        }
 
65
        else
 
66
        {
 
67
            pos = -1;
 
68
        }
 
69
    }
 
70
 
 
71
    return match;
 
72
}
 
73