Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

TextFileSearcherRegEx.cpp

/***************************************************************
 * Name:      TextFileSearcherRegEx
 * Purpose:   TextFileSearcherRegEx is used to search text files
 *            for regular expressions.
 * Author:    Jerome ANTOINE
 * Created:   2007-04-07
 * Copyright: Jerome ANTOINE
 * License:   GPL
 **************************************************************/

#include "sdk.h"
#ifndef CB_PRECOMP
      // Required extra includes
      #include <wx/string.h>
#endif

#include "TextFileSearcherRegEx.h"


00020 TextFileSearcherRegEx::TextFileSearcherRegEx(const wxString& searchText, bool matchCase, bool matchWordBegin,
                                                                  bool matchWord)
                                :TextFileSearcher(searchText, matchCase, matchWordBegin, matchWord)
{
      wxString pattern = searchText;

#ifdef wxHAS_REGEX_ADVANCED
    int flags = wxRE_ADVANCED;
#else
    int flags = wxRE_EXTENDED;
#endif
      if ( matchCase == false )
      {
            flags |= wxRE_ICASE;
      }

      if ( matchWord == true )
      {
            pattern = _T("([^[:alnum:]_]|^)") + pattern + _T("([^[:alnum:]_]|$)");
      }
      else if ( matchWordBegin == true )
      {
            pattern = _T("([^[:alnum:]_]|^)") + pattern;
      }

      m_RegEx.Compile(pattern, flags);
}


00049 bool TextFileSearcherRegEx::MatchLine(wxString line)
{
      bool match = false;
      if ( m_RegEx.IsValid() )
      {
            match = m_RegEx.Matches(line.c_str());
      }
      return match;
}


00060 bool TextFileSearcherRegEx::IsOk(wxString* pErrorMessage)
{
      bool ok = m_RegEx.IsValid();
      if ( !ok && pErrorMessage )
      {
            *pErrorMessage = _T("Bad regular expression.");
      }
      return ok;
}

Generated by  Doxygen 1.6.0   Back to index