Bläddra i källkod

Added regular expression filtering

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@754 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 10 år sedan
förälder
incheckning
183d24f5d1
8 ändrade filer med 73 tillägg och 5 borttagningar
  1. 3 1
      CP_Main.rc
  2. 7 2
      FormatSQL.cpp
  3. 10 0
      Options.cpp
  4. 5 0
      Options.h
  5. 11 1
      QPasteWnd.cpp
  6. 1 0
      QPasteWnd.h
  7. 2 1
      Resource.h
  8. 34 0
      sqlite/CppSQLite3.cpp

+ 3 - 1
CP_Main.rc

@@ -333,7 +333,9 @@ BEGIN
         MENUITEM "Search Description",          ID_MENU_SEARCHDESCRIPTION
         MENUITEM "Search Full Text",            ID_MENU_SEARCHFULLTEXT
         MENUITEM "Search Quick Paste",          ID_MENU_SEARCHQUICKPASTE
-        MENUITEM "Contains Text Search Only",   ID_MENU_CONTAINSTEXTSEARCHONLY
+        MENUITEM SEPARATOR
+        MENUITEM "Contains Text Search",        ID_MENU_CONTAINSTEXTSEARCHONLY
+        MENUITEM "Regular Expression Search",   ID_MENU_REGULAREXPRESSIONSEARCH
     END
 END
 

+ 7 - 2
FormatSQL.cpp

@@ -33,7 +33,8 @@ void CFormatSQL::Parse(CString cs)
 	//Replace all "|" with a space
 	cs.Replace(_T("|"), _T(" "));
 
-	if(CGetSetOptions::GetSimpleTextSearch())
+	if(CGetSetOptions::GetSimpleTextSearch() ||
+		CGetSetOptions::GetRegExTextSearch())
 	{
 		eSpecialTypes invalid = eINVALID;
 		AddToSQL(cs, invalid, invalid);
@@ -135,7 +136,11 @@ bool CFormatSQL::AddToSQL(CString cs, eSpecialTypes &eNOTValue, eSpecialTypes &e
 	cs.TrimLeft();
 	cs.TrimRight();
 
-	if (CGetSetOptions::GetSimpleTextSearch())
+	if (CGetSetOptions::GetRegExTextSearch())
+	{
+		csThisSQL.Format(_T("%s REGEXP \'%s\'"), m_csVariable, cs);
+	}
+	else if (CGetSetOptions::GetSimpleTextSearch())
 	{
 		csThisSQL.Format(_T("%s LIKE \'%%%s%%\'"), m_csVariable, cs);
 	}

+ 10 - 0
Options.cpp

@@ -2048,6 +2048,16 @@ BOOL CGetSetOptions::GetSimpleTextSearch()
 	return GetProfileLong(_T("SimpleTextSearch"), 0);
 }
 
+void CGetSetOptions::SetRegExTextSearch(BOOL val)
+{
+	SetProfileLong(_T("RegExTextSearch"), val);
+}
+
+BOOL CGetSetOptions::GetRegExTextSearch()
+{
+	return GetProfileLong(_T("RegExTextSearch"), 0);
+}
+
 void CGetSetOptions::SetMoveClipsOnGlobal10(BOOL val)
 {
 	SetProfileLong(_T("MoveClipsOnGlobal10"), val);

+ 5 - 0
Options.h

@@ -463,6 +463,11 @@ public:
 
 	static void		SetQRCodeBorderPixels(int val);
 	static int	GetQRCodeBorderPixels();
+
+	static BOOL GetRegExTextSearch();
+	static void SetRegExTextSearch(BOOL val);
+
+
 };
 
 // global for easy access and for initialization of fast access variables

+ 11 - 1
QPasteWnd.cpp

@@ -220,6 +220,7 @@ ON_UPDATE_COMMAND_UI(ID_COMPARE_COMPARE, &CQPasteWnd::OnUpdateCompareCompare)
 ON_MESSAGE(NM_SHOW_PROPERTIES, OnShowProperties)
 ON_MESSAGE(NM_NEW_GROUP, OnNewGroup)
 ON_MESSAGE(NM_DELETE_ID, OnDeleteId)
+ON_COMMAND(ID_MENU_REGULAREXPRESSIONSEARCH, &CQPasteWnd::OnMenuRegularexpressionsearch)
 END_MESSAGE_MAP()
 
 
@@ -4042,6 +4043,9 @@ void CQPasteWnd::OnSearchDescription()
 
 		if(CGetSetOptions::GetSimpleTextSearch())
 			cmSubMenu->CheckMenuItem(ID_MENU_CONTAINSTEXTSEARCHONLY, MF_CHECKED);
+
+		if (CGetSetOptions::GetRegExTextSearch())
+			cmSubMenu->CheckMenuItem(ID_MENU_REGULAREXPRESSIONSEARCH, MF_CHECKED);
 				
 
 		//theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
@@ -4629,4 +4633,10 @@ LRESULT CQPasteWnd::OnDeleteId(WPARAM wParam, LPARAM lParam)
 	DeleteClips(IDs, Indexs);
 
 	return TRUE;
-}
+}
+
+void CQPasteWnd::OnMenuRegularexpressionsearch()
+{
+	CGetSetOptions::SetSimpleTextSearch(FALSE);
+	CGetSetOptions::SetRegExTextSearch(!CGetSetOptions::GetRegExTextSearch());
+}

+ 1 - 0
QPasteWnd.h

@@ -399,4 +399,5 @@ public:
 	afx_msg LRESULT OnShowProperties(WPARAM wParam, LPARAM lParam);
 	afx_msg LRESULT OnNewGroup(WPARAM wParam, LPARAM lParam);
 	afx_msg LRESULT OnDeleteId(WPARAM wParam, LPARAM lParam);
+	afx_msg void OnMenuRegularexpressionsearch();
 };

+ 2 - 1
Resource.h

@@ -492,6 +492,7 @@
 #define ID_MENU_NEWGROUP32896           32896
 #define ID_MENU_DELETEGROUP             32897
 #define ID_MENU_PROPERTIES32898         32898
+#define ID_MENU_REGULAREXPRESSIONSEARCH 32899
 
 // Next default values for new objects
 // 
@@ -499,7 +500,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        240
-#define _APS_NEXT_COMMAND_VALUE         32899
+#define _APS_NEXT_COMMAND_VALUE         32900
 #define _APS_NEXT_CONTROL_VALUE         2127
 #define _APS_NEXT_SYMED_VALUE           101
 #endif

+ 34 - 0
sqlite/CppSQLite3.cpp

@@ -29,6 +29,7 @@
 #include "CppSQLite3.h"
 #include <cstdlib>
 #include "..\UnicodeMacros.h"
+#include <regex>
 
 
 // Named constant for passing to CppSQLite3Exception when passing it a string
@@ -750,6 +751,35 @@ CppSQLite3DB& CppSQLite3DB::operator=(const CppSQLite3DB& db)
 	return *this;
 }
 
+void sqlite_regexp(sqlite3_context* context, int argc, sqlite3_value** values)
+{
+	char* reg = (char*) sqlite3_value_text(values[0]);
+	char* text = (char*) sqlite3_value_text(values[1]);
+
+	if (argc != 2 || reg == 0 || text == 0) 
+	{
+		sqlite3_result_error(context, "SQL function regexp() called with invalid arguments.\n", -1);
+		return;
+	}
+
+	try
+	{
+		if (std::regex_search(text, std::regex(reg)))
+		{
+			sqlite3_result_int(context, 1);
+		}
+		else
+		{
+			sqlite3_result_int(context, 0);
+		}
+	}
+	catch (std::regex_error& e) 
+	{
+		CStringA r;
+		r.Format("regex_search exception %d, reg: %s, str: %s", e.code(), reg, text);
+		OutputDebugStringA(r);
+	}
+}
 
 void CppSQLite3DB::open(const TCHAR* szFile)
 {
@@ -765,10 +795,14 @@ void CppSQLite3DB::open(const TCHAR* szFile)
 		throw CppSQLite3Exception(nRet, (TCHAR*)szError, DONT_DELETE_MSG);
 	}
 
+	int ret = sqlite3_create_function(mpDB, "regexp", 2, SQLITE_ANY, 0, &sqlite_regexp, 0, 0);
+
 	setBusyTimeout(mnBusyTimeoutMs);
 }
 
 
+
+
 bool CppSQLite3DB::close()
 {
 	bool bRet = true;