~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
#include <sdk.h> // Code::Blocks SDK
12
12
#ifndef CB_PRECOMP
13
 
        #include <globals.h>
 
13
    #include <globals.h>
14
14
#endif
15
15
 
 
16
#include "encodingdetector.h"
 
17
 
16
18
#include <wx/filename.h>
17
19
 
18
20
#include "TextFileSearcher.h"
21
23
 
22
24
 
23
25
TextFileSearcher* TextFileSearcher::BuildTextFileSearcher(const wxString& searchText,
24
 
                                                                                                                  bool matchCase,
25
 
                                                                                                                  bool matchWordBegin,
26
 
                                                                                                                  bool matchWord,
27
 
                                                                                                                  bool regEx)
 
26
                                                          bool matchCase,
 
27
                                                          bool matchWordBegin,
 
28
                                                          bool matchWord,
 
29
                                                          bool regEx)
28
30
{
29
 
        TextFileSearcher* pFileSearcher = NULL;
30
 
        if ( regEx == true )
31
 
        {
32
 
                pFileSearcher = new TextFileSearcherRegEx(searchText, matchCase, matchWordBegin, matchWord);
33
 
        }
34
 
        else
35
 
        {
36
 
                pFileSearcher = new TextFileSearcherText(searchText, matchCase, matchWordBegin, matchWord);
37
 
        }
38
 
 
39
 
        // Tests if construction is OK
40
 
        wxString errorMessage(wxEmptyString);
41
 
        if ( pFileSearcher && !pFileSearcher->IsOk(&errorMessage)  )
42
 
        {
43
 
                delete pFileSearcher;
44
 
                pFileSearcher = 0;
45
 
        }
46
 
 
47
 
        return pFileSearcher;
 
31
    TextFileSearcher* pFileSearcher = NULL;
 
32
    if ( regEx == true )
 
33
    {
 
34
        pFileSearcher = new TextFileSearcherRegEx(searchText, matchCase, matchWordBegin, matchWord);
 
35
    }
 
36
    else
 
37
    {
 
38
        pFileSearcher = new TextFileSearcherText(searchText, matchCase, matchWordBegin, matchWord);
 
39
    }
 
40
 
 
41
    // Tests if construction is OK
 
42
    wxString errorMessage(wxEmptyString);
 
43
    if ( pFileSearcher && !pFileSearcher->IsOk(&errorMessage)  )
 
44
    {
 
45
        delete pFileSearcher;
 
46
        pFileSearcher = 0;
 
47
    }
 
48
 
 
49
    return pFileSearcher;
48
50
}
49
51
 
50
52
 
51
53
TextFileSearcher::eFileSearcherReturn TextFileSearcher::FindInFile(const wxString& filePath, wxArrayString &foundLines)
52
54
{
53
 
        eFileSearcherReturn success=idStringNotFound;
54
 
        wxString line;
55
 
 
56
 
        // Tests file existence
57
 
        if ( !wxFileName::FileExists(filePath) )
58
 
        {
59
 
                // We skip missing files without alerting user.
60
 
                // If a file has disappeared, it is not our problem.
61
 
                // cbMessageBox( filePath + _T(" does not exist."), _T("Error"), wxICON_ERROR);
62
 
                return idFileNotFound;
63
 
        }
64
 
 
65
 
        // File open
66
 
        if ( !m_TextFile.Open(filePath, wxConvFile) )
67
 
        {
68
 
                return idFileOpenError;
69
 
        }
70
 
 
71
 
        // Tests all file lines
72
 
        for ( size_t i = 0; i < m_TextFile.GetLineCount(); ++i )
73
 
        {
74
 
                line = m_TextFile.GetLine(i);
75
 
                if ( MatchLine(line) )
76
 
                {
77
 
                        success=idStringFound;
78
 
                        // An interesting line is found. We clean and add it to the provided array
79
 
                        line.Replace(_T("\t"), _T(" "));
80
 
                        line.Replace(_T("\r"), _T(" "));
81
 
                        line.Replace(_T("\n"), _T(" "));
82
 
                        line.Trim(false);
83
 
                        line.Trim(true);
84
 
 
85
 
                        foundLines.Add(wxString::Format(wxT("%d"), i + 1));
86
 
                        foundLines.Add(line);
87
 
                }
88
 
        }
89
 
 
90
 
        // File close
91
 
        m_TextFile.Close();
92
 
 
93
 
        return success;
 
55
    eFileSearcherReturn success=idStringNotFound;
 
56
    wxString line;
 
57
 
 
58
    // skip empty fles
 
59
    if(wxFileName::GetSize(filePath) != 0)
 
60
    {
 
61
        // Tests file size and existence
 
62
        if ( !wxFileName::FileExists(filePath) )
 
63
        {
 
64
            // We skip missing files without alerting user.
 
65
            // If a file has disappeared, it is not our problem.
 
66
            // cbMessageBox( filePath + _T(" does not exist."), _T("Error"), wxICON_ERROR);
 
67
            return idFileNotFound;
 
68
        }
 
69
 
 
70
        // File open
 
71
        EncodingDetector enc(filePath, false);
 
72
        if( !enc.IsOK())
 
73
        {
 
74
    //        return idFileOpenError;
 
75
            return idFileNotFound;
 
76
        }
 
77
        wxFontEncoding fe =  enc.GetFontEncoding();
 
78
 
 
79
        if ( fe == wxFONTENCODING_UTF7 )
 
80
        {
 
81
            wxMBConvUTF7 conv;
 
82
            if ( !m_TextFile.Open(filePath, conv) )
 
83
            {
 
84
                return idFileOpenError;
 
85
            }
 
86
        }
 
87
        else if ( fe == wxFONTENCODING_UTF8 )
 
88
        {
 
89
            wxMBConvUTF8 conv;
 
90
            if ( !m_TextFile.Open(filePath, conv) )
 
91
            {
 
92
                return idFileOpenError;
 
93
            }
 
94
        }
 
95
        else if ( fe == wxFONTENCODING_UTF16BE )
 
96
        {
 
97
            wxMBConvUTF16BE conv;
 
98
            if ( !m_TextFile.Open(filePath, conv) )
 
99
            {
 
100
                return idFileOpenError;
 
101
            }
 
102
        }
 
103
        else if ( fe == wxFONTENCODING_UTF16LE )
 
104
        {
 
105
            wxMBConvUTF16LE conv;
 
106
            if ( !m_TextFile.Open(filePath, conv) )
 
107
            {
 
108
                return idFileOpenError;
 
109
            }
 
110
        }
 
111
        else if ( fe == wxFONTENCODING_UTF32BE )
 
112
        {
 
113
            wxMBConvUTF32BE conv;
 
114
            if ( !m_TextFile.Open(filePath, conv) )
 
115
            {
 
116
                return idFileOpenError;
 
117
            }
 
118
        }
 
119
        else if ( fe == wxFONTENCODING_UTF32LE )
 
120
        {
 
121
            wxMBConvUTF32LE conv;
 
122
            if ( !m_TextFile.Open(filePath, conv) )
 
123
            {
 
124
                return idFileOpenError;
 
125
            }
 
126
        }
 
127
        else
 
128
        {
 
129
            wxCSConv conv(fe);
 
130
            if ( !m_TextFile.Open(filePath, conv) )
 
131
            {
 
132
                return idFileOpenError;
 
133
            }
 
134
 
 
135
        }
 
136
 
 
137
 
 
138
        // Tests all file lines
 
139
        for ( size_t i = 0; i < m_TextFile.GetLineCount(); ++i )
 
140
        {
 
141
            line = m_TextFile.GetLine(i);
 
142
            if ( MatchLine(line) )
 
143
            {
 
144
                success=idStringFound;
 
145
                // An interesting line is found. We clean and add it to the provided array
 
146
                line.Replace(_T("\t"), _T(" "));
 
147
                line.Replace(_T("\r"), _T(" "));
 
148
                line.Replace(_T("\n"), _T(" "));
 
149
                line.Trim(false);
 
150
                line.Trim(true);
 
151
 
 
152
                foundLines.Add(wxString::Format(wxT("%d"), i + 1));
 
153
                foundLines.Add(line);
 
154
            }
 
155
        }
 
156
 
 
157
        // File close
 
158
        m_TextFile.Close();
 
159
    }
 
160
    return success;
94
161
}
95
162
 
96
163
 
97
164
bool TextFileSearcher::IsOk(wxString* WXUNUSED(pErrorMessage))
98
165
{
99
 
        return true;
 
166
    return true;
100
167
}