~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************
 
2
 * Name:      TextFileSearcherRegEx
 
3
 * Purpose:   TextFileSearcherRegEx is used to search text files
 
4
 *            for regular expressions.
 
5
 * Author:    Jerome ANTOINE
 
6
 * Created:   2007-04-07
 
7
 * Copyright: Jerome ANTOINE
 
8
 * License:   GPL
 
9
 **************************************************************/
 
10
 
 
11
#include "sdk.h"
 
12
#ifndef CB_PRECOMP
 
13
        // Required extra includes
 
14
        #include <wx/string.h>
 
15
#endif
 
16
 
 
17
#include "TextFileSearcherRegEx.h"
 
18
 
 
19
 
 
20
TextFileSearcherRegEx::TextFileSearcherRegEx(const wxString& searchText, bool matchCase, bool matchWordBegin,
 
21
                                                                                        bool matchWord)
 
22
                                          :TextFileSearcher(searchText, matchCase, matchWordBegin, matchWord)
 
23
{
 
24
        wxString pattern = searchText;
 
25
 
 
26
#ifdef wxHAS_REGEX_ADVANCED
 
27
    int flags = wxRE_ADVANCED;
 
28
#else
 
29
    int flags = wxRE_EXTENDED;
 
30
#endif
 
31
        if ( matchCase == false )
 
32
        {
 
33
                flags |= wxRE_ICASE;
 
34
        }
 
35
 
 
36
        if ( matchWord == true )
 
37
        {
 
38
                pattern = _T("([^[:alnum:]_]|^)") + pattern + _T("([^[:alnum:]_]|$)");
 
39
        }
 
40
        else if ( matchWordBegin == true )
 
41
        {
 
42
                pattern = _T("([^[:alnum:]_]|^)") + pattern;
 
43
        }
 
44
 
 
45
        m_RegEx.Compile(pattern, flags);
 
46
}
 
47
 
 
48
 
 
49
bool TextFileSearcherRegEx::MatchLine(wxString line)
 
50
{
 
51
        bool match = false;
 
52
        if ( m_RegEx.IsValid() )
 
53
        {
 
54
                match = m_RegEx.Matches(line.c_str());
 
55
        }
 
56
        return match;
 
57
}
 
58
 
 
59
 
 
60
bool TextFileSearcherRegEx::IsOk(wxString* pErrorMessage)
 
61
{
 
62
        bool ok = m_RegEx.IsValid();
 
63
        if ( !ok && pErrorMessage )
 
64
        {
 
65
                *pErrorMessage = _T("Bad regular expression.");
 
66
        }
 
67
        return ok;
 
68
}