2006-11-07 Kimmo
Add PCRE 6.7 (with windows build files from ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib/)
New folder: /Externals/pcre
+ PATCH: [ 1591605 ] Add PCRE regexps and convert file filtering to PCRE
+ Src: FileFilterMgr.cpp FileFilterMgr.h Merge.dsp Plugins.cpp
+ Src new files: Ucs2Utf8.cpp Ucs2Utf8.h
2006-11-06 Takashi
PATCH: [ 1586705 ] DirView icons (Tim made [not]equalfile.ico)
// see FileFilterMgr.h for description
/////////////////////////////////////////////////////////////////////////////
// License (GPLv2+):
-// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
-// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-// You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2 of the License, or (at your
+// option) any later version.
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
/////////////////////////////////////////////////////////////////////////////
/**
* @file FileFilterMgr.cpp
// $Id$
#include "stdafx.h"
+#include <string.h>
+#include "pcre.h"
#include "FileFilterMgr.h"
-#include "RegExp.h"
#include "UniFile.h"
#include "coretools.h"
+#include "Ucs2Utf8.h"
#ifdef _DEBUG
#define new DEBUG_NEW
while (!filterList.IsEmpty())
{
FileFilterElement &elem = filterList.GetHead();
- delete elem.pRegExp;
+ pcre_free(elem.pRegExp);
+ pcre_free(elem.pRegExpExtra);
filterList.RemoveHead();
}
}
if (str.IsEmpty())
return;
- CRegExp * regexp = new CRegExp;
+ const char * errormsg = NULL;
+ int erroroffset = 0;
+ char regexString[200] = {0};
+ int regexLen = 0;
+ int pcre_opts = 0;
+
+#ifdef UNICODE
+ // For unicode builds, use UTF-8.
+ // Convert pattern to UTF-8 and set option for PCRE to specify UTF-8.
+ regexLen = TransformUcs2ToUtf8((LPCTSTR)str, _tcslen(str),
+ regexString, sizeof(regexString));
+ pcre_opts |= PCRE_UTF8;
+#else
+ strcpy(regexString, (LPCTSTR)str);
+ regexLen = strlen(regexString);
+#endif
+
+ pcre *regexp = pcre_compile(regexString, pcre_opts, &errormsg,
+ &erroroffset, NULL);
if (regexp)
{
- if (regexp->RegComp(str))
- {
- FileFilterElement elem;
- elem.pRegExp = regexp;
+ FileFilterElement elem;
+ errormsg = NULL;
+
+ pcre_extra *pe = pcre_study(regexp, 0, &errormsg);
+ elem.pRegExp = regexp;
- filterList.AddTail(elem);
- }
- else
- delete regexp;
+ if (pe != NULL && errormsg != NULL)
+ elem.pRegExpExtra = pe;
+
+ filterList.AddTail(elem);
}
}
*/
BOOL TestAgainstRegList(const FileFilterList & filterList, LPCTSTR szTest)
{
- CString str = szTest;
- str.MakeUpper();
for (POSITION pos = filterList.GetHeadPosition(); pos; )
{
const FileFilterElement & elem = filterList.GetNext(pos);
- CRegExp * regexp = elem.pRegExp;
- if (regexp->RegFind(str) != -1)
+ int ovector[30];
+ char compString[200] = {0};
+ int stringLen = 0;
+ TCHAR * tempName = _tcsdup(szTest); // Create temp copy for conversions
+ TCHAR * cmpStr = _tcsupr(tempName);
+
+#ifdef UNICODE
+ stringLen = TransformUcs2ToUtf8(cmpStr, _tcslen(cmpStr),
+ compString, sizeof(compString));
+#else
+ strcpy(compString, cmpStr);
+ stringLen = strlen(compString);
+#endif
+
+ pcre * regexp = elem.pRegExp;
+ pcre_extra * extra = elem.pRegExpExtra;
+ int result = pcre_exec(regexp, extra, compString, stringLen,
+ 0, 0, ovector, 30);
+
+ free(tempName);
+
+ if (result >= 0)
return TRUE;
}
return FALSE;
/////////////////////////////////////////////////////////////////////////////
-// FileFilterMgr.h : declaration file
-//
-// The FileFilterMgr loads a collection of named file filters from disk,
-// and provides lookup access by name, or array access by index, to these
-// named filters. It also provides test functions for actually using the filters.
-/////////////////////////////////////////////////////////////////////////////
// License (GPLv2+):
-// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
-// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-// You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
/////////////////////////////////////////////////////////////////////////////
/**
* @file FileFilterMgr.h
#ifndef __AFXTEMPL_H__
#include <afxtempl.h>
#endif
+#include "pcre.h"
-class CRegExp;
struct FileFilterElement;
/**
* @brief List of file filtering rules.
* regular expression there is boolean value for defining if rule
* is inclusive or exclusive. File filters have global inclusive/exclusive
* selection but this per-rule setting overwrites it.
+ *
+ * We are using PCRE for regular expressions and pRegExp points to compiled
+ * regular expression. pRegExpExtra contains additional information about
+ * the expression used to optimize matching.
*/
struct FileFilterElement
{
- CRegExp *pRegExp; /**< Pointer to regexp */
- CString sRule; /**< Uncompiled rule text */
- FileFilterElement() : pRegExp(NULL) { };
+ pcre *pRegExp; /**< Compiled regular expression */
+ pcre_extra *pRegExpExtra; /**< Additional information got from regex study */
+ FileFilterElement() : pRegExp(NULL), pRegExpExtra(NULL) { };
};
struct FileFilter;
*
* The FileFilterMgr loads a collection of named file filters from disk,
* and provides lookup access by name, or array access by index, to these
- * named filters. It also provides test functions for actually using the filters.
+ * named filters. It also provides test functions for actually using the
+ * filters.
+ *
+ * We are using PCRE for regular expressions. Nice thing in PCRE is it supports
+ * UTF-8 unicode, unlike many other libs. For ANSI builds we use just ansi
+ * strings, and for unicode we must first convert strings to UTF-8.
*/
class FileFilterMgr
{
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /EHa /c
-# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /FR /Yu"stdafx.h" /FD /EHa /c
+# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /I "..\Externals\pcre\pcre-6.7" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /FR /Yu"stdafx.h" /FD /EHa /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
# ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL"
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpat.lib /nologo /subsystem:windows /debug /machine:I386 /out:"..\Build\MergeDebug/WinMerge.exe" /pdbtype:sept /libpath:"..\Build\expat"
+# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpat.lib pcre.lib /nologo /subsystem:windows /debug /machine:I386 /out:"..\Build\MergeDebug/WinMerge.exe" /pdbtype:sept /libpath:"..\Build\expat" /libpath:"..\Build\pcre"
!ELSEIF "$(CFG)" == "Merge - Win32 UnicodeDebug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I "..\common" /I ".\editlib" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /FR /Yu"stdafx.h" /FD /EHa /c
-# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /D "XML_UNICODE_WCHAR_T" /FR /Yu"stdafx.h" /FD /EHa /c
+# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /I "..\Externals\pcre\pcre-6.7" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /D "XML_UNICODE_WCHAR_T" /FR /Yu"stdafx.h" /FD /EHa /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
# ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL"
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 version.lib shlwapi.lib /nologo /subsystem:windows /debug /machine:I386 /out:"..\Build\MergeUnicodeDebug/WinMerge.exe" /pdbtype:sept
-# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpatw.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /out:"..\Build\MergeUnicodeDebug/WinMergeU.exe" /pdbtype:sept /libpath:"..\Build\expat"
+# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpatw.lib pcre.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /out:"..\Build\MergeUnicodeDebug/WinMergeU.exe" /pdbtype:sept /libpath:"..\Build\expat" /libpath:"..\Build\pcre"
!ELSEIF "$(CFG)" == "Merge - Win32 Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MD /W4 /GR /GX /Zi /O1 /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /Yu"stdafx.h" /FD /EHa /c
-# ADD CPP /nologo /MD /W3 /GR /GX /Zi /O1 /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /Yu"stdafx.h" /FD /EHa /c
+# ADD CPP /nologo /MD /W3 /GR /GX /Zi /O1 /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /I "..\Externals\pcre\pcre-6.7" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /Yu"stdafx.h" /FD /EHa /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
# ADD BASE RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL"
LINK32=link.exe
# ADD BASE LINK32 version.lib shlwapi.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\Build\MergeRelease/WinMerge.exe" /verbose:lib
# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpat.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\Build\MergeRelease/WinMerge.exe" /libpath:"..\Build\expat" /verbose:lib
+# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpat.lib pcre.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\Build\MergeRelease/WinMerge.exe" /libpath:"..\Build\expat" /libpath:"..\Build\pcre" /verbose:lib
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "Merge - Win32 UnicodeRelease"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MD /W4 /GR /GX /Zi /O1 /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /Yu"stdafx.h" /FD /EHa /c
-# ADD CPP /nologo /MD /W3 /GR /GX /Zi /O1 /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /D "XML_UNICODE_WCHAR_T" /Yu"stdafx.h" /FD /EHa /c
+# ADD CPP /nologo /MD /W3 /GR /GX /Zi /O1 /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /I "..\Externals\pcre\pcre-6.7" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /D "XML_UNICODE_WCHAR_T" /Yu"stdafx.h" /FD /EHa /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
# ADD BASE RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL"
LINK32=link.exe
# ADD BASE LINK32 version.lib shlwapi.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\Build\MergeUnicodeRelease\WinMergeU.exe" /verbose:lib
# SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpatw.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\Build\MergeUnicodeRelease\WinMergeU.exe" /libpath:"..\Build\expat" /verbose:lib
+# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpatw.lib pcre.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\Build\MergeUnicodeRelease\WinMergeU.exe" /libpath:"..\Build\expat" /libpath:"..\Build\pcre" /verbose:lib
# SUBTRACT LINK32 /pdb:none
!ENDIF
# End Source File
# Begin Source File
+SOURCE=.\Ucs2Utf8.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\Common\unicoder.cpp
# End Source File
# Begin Source File
# End Source File
# Begin Source File
+SOURCE=.\Ucs2Utf8.h
+# End Source File
+# Begin Source File
+
SOURCE=.\Common\unicoder.h
# End Source File
# Begin Source File
#include <afxmt.h>
#endif
+#include "pcre.h"
+#include "Ucs2Utf8.h"
#include "FileTransform.h"
#include "FileFilterMgr.h"
#include "Plugins.h"
#include "lwdisp.h"
#include "coretools.h"
-#include "RegExp.h"
+//#include "RegExp.h"
#include "resource.h"
#include "Exceptions.h"
#include "RegKey.h"
sPiece.TrimLeft();
sPiece.MakeUpper();
- CRegExp * regexp = new CRegExp;
+// CRegExp * regexp = new CRegExp;
FileFilterElement element;
- if (regexp->RegComp(sPiece))
+/* if (regexp->RegComp(sPiece))
{
element.pRegExp = regexp;
filters->AddTail(element);
}
else
delete regexp;
+*/
+ const char * errormsg = NULL;
+ //char errormsg[200] = {0};
+ int erroroffset = 0;
+ char regexString[200] = {0};
+ int regexLen = 0;
+#ifdef UNICODE
+ regexLen = TransformUcs2ToUtf8((LPCTSTR)sPiece, _tcslen(sPiece),
+ regexString, sizeof(regexString));
+#else
+ strcpy(regexString, (LPCTSTR)sPiece);
+ regexLen = strlen(regexString);
+#endif
+
+ pcre *regexp = pcre_compile(regexString, 0, &errormsg, &erroroffset, NULL);
+ if (regexp)
+ {
+ FileFilterElement elem;
+ elem.pRegExp = regexp;
+ filters->AddTail(elem);
+ }
+
};
}
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////\r
+// License (GPLv2+):\r
+// This program is free software; you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation; either version 2 of the License, or (at\r
+// your option) any later version.\r
+// \r
+// This program is distributed in the hope that it will be useful, but\r
+// WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+/////////////////////////////////////////////////////////////////////////////\r
+/** \r
+ * @file Ucs2Utf8.cpp\r
+ *\r
+ * @brief UCS-2 <--> UTF-8 conversion routines implementation.\r
+ */\r
+\r
+#include "stdafx.h"\r
+#include "unicoder.h"\r
+#include "Ucs2Utf8.h"\r
+\r
+/**\r
+ * @brief Copy UCS-2LE string to UTF-8 string\r
+ *\r
+ * @param nUcs is the size in wide characters of the source string\r
+ * @param nUtf is the size in bytes of the resulting string\r
+ *\r
+ * @return if nUtf = 0, return the size required for the translation buffer\r
+ */\r
+UINT TransformUcs2ToUtf8(LPCWSTR psUcs, UINT nUcs, LPSTR pcsUtf, UINT nUtf)\r
+{\r
+ if (nUtf == 0)\r
+ // just tell required length\r
+ return ucr::Utf8len_of_string(psUcs, nUcs);\r
+\r
+ // the buffer is allocated, output in it directly\r
+ unsigned char * pc = (unsigned char *) pcsUtf;\r
+ int nremains = nUtf;\r
+\r
+ // quick way \r
+ UINT i=0;\r
+ for (i = 0 ; i < nUcs && nremains > 10; ++i)\r
+ nremains -= ucr::to_utf8_advance(psUcs[i], pc);\r
+\r
+ // be careful for the end of the buffer, risk of overflow because\r
+ // of the variable length of the UTF-8 character\r
+ unsigned char smallTempBuffer[20];\r
+ int nremainsend = nremains;\r
+ unsigned char * pcTemp = (unsigned char *) smallTempBuffer;\r
+ for ( ; i < nUcs && nremainsend > 0; ++i)\r
+ nremainsend -= ucr::to_utf8_advance(psUcs[i], pcTemp);\r
+\r
+ int ncomplement = min(nremains, pcTemp-smallTempBuffer);\r
+ CopyMemory(pc, smallTempBuffer, ncomplement);\r
+ nremains -= ncomplement;\r
+\r
+ // return number of written bytes\r
+ return (nUtf - nremains);\r
+}\r
+\r
+/**\r
+ * @brief Copy UTF-8 string to UCS-2LE string\r
+ *\r
+ * @return if nUcs = 0, return the size required for the translation buffer\r
+ */\r
+UINT TransformUtf8ToUcs2(LPCSTR pcsUtf, UINT nUtf, LPWSTR psUcs, UINT nUcs)\r
+{\r
+ if (nUcs == 0)\r
+ // just tell required length\r
+ return ucr::stringlen_of_utf8(pcsUtf, nUtf);\r
+\r
+ // the buffer is allocated, output in it directly\r
+ unsigned char * pUtf = (unsigned char * ) pcsUtf;\r
+ LPWSTR pwc = psUcs;\r
+ int nremains = nUcs;\r
+\r
+ for (UINT i = 0 ; i < nUtf && nremains > 0; )\r
+ {\r
+ *pwc++ = ucr::GetUtf8Char(pUtf+i);\r
+ nremains --;\r
+ int chlen = ucr::Utf8len_fromLeadByte(pUtf[i]);\r
+ if (chlen < 1) chlen = 1;\r
+ i += chlen;\r
+ }\r
+\r
+ // return number of written wchars\r
+ return (nUtf - nremains);\r
+}\r
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////\r
+// License (GPLv2+):\r
+// This program is free software; you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation; either version 2 of the License, or\r
+// (at your option) any later version.\r
+//\r
+// This program is distributed in the hope that it will be useful, but\r
+// WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+// General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+/////////////////////////////////////////////////////////////////////////////\r
+/**\r
+ * @file Ucs2Utf8.h\r
+ *\r
+ * @brief Declaration for UCS-2 <--> UTF-8 conversions functions.\r
+ *\r
+ */\r
+\r
+#ifndef _UCS2UTF8_H_\r
+#define _UCS2UTF8_H_\r
+\r
+UINT TransformUcs2ToUtf8(LPCWSTR psUcs, UINT nUcs, LPSTR pcsUtf, UINT nUtf);\r
+UINT TransformUtf8ToUcs2(LPCSTR pcsUtf, UINT nUtf, LPWSTR psUcs, UINT nUcs);\r
+\r
+#endif // _UCS2UTF8_H_\r