Skip to content

Commit 4527e25

Browse files
1.0.0.5 Enhancements and fixes
1. Alternate color token list. 2. Additional compatibilities 3. Added ability to change compatibility using up and down keys while cursor is in expression field. 4. Implemented logic for all std::regex and boost::regex types to do whole body search and replace. 5. Added additional tokens. 6. Added additional SAMPLE column to the token list.
1 parent c0fdaa1 commit 4527e25

18 files changed

+2696
-822
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ RegexAssistant_i.c
2525
/bin
2626
/.vs
2727
/enc_temp_folder
28+
/RegexLibs
2829
*.aps
2930
RegexAssistant.7z
3031
Docs/ProjectImages/RegexAssistant_DefaultStartupScreenSet2.png
3132
Wix.xml
33+
PaternsExamplesToAdd.txt
34+
*.7z
35+
*.swp

RegexAssistant/CommonFunction.cpp

Lines changed: 174 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,192 @@
55
*/
66
#include "pch.h"
77
#include "CommonFunctions.h"
8-
#include <string>
9-
#include <codecvt>
10-
#include <locale>
118
#include <boost/algorithm/string/replace.hpp>
129

13-
namespace FXString
10+
11+
12+
namespace Common
1413
{
15-
std::wstring ToWString(std::string src) {
16-
return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(src);
14+
std::wstring ToWString(std::string str )
15+
{
16+
if ( str.empty() ) return std::wstring();
17+
int size_needed = MultiByteToWideChar( CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0 );
18+
std::wstring wstrTo( size_needed, 0 );
19+
MultiByteToWideChar( CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed );
20+
return wstrTo;
1721
}
1822

19-
std::string ToString(std::wstring src ) {
20-
return std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(src);
23+
std::string ToString(std::wstring wstr )
24+
{
25+
if ( wstr.empty() ) return std::string();
26+
int size_needed = WideCharToMultiByte( CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL );
27+
std::string strTo( size_needed, 0 );
28+
WideCharToMultiByte( CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL );
29+
return strTo;
2130
}
2231

23-
void ReplaceAll(std::string &str, const std::string &searchStr, const std::string &ReplacementStr) {
24-
boost::replace_all(str, searchStr, ReplacementStr);
32+
void ReplaceAll( std::string &src, const std::string &searchStr, const std::string &ReplacementStr )
33+
{
34+
boost::replace_all( src, searchStr, ReplacementStr );
2535
}
2636

27-
std::string CopyAndReplaceAll(std::string str, const std::string &searchStr, const std::string &ReplacementStr)
37+
std::string Replace( std::string &src, const std::string &searchStr, const std::string &ReplacementStr )
2838
{
39+
ReplaceAll( src, searchStr, ReplacementStr );
40+
return src;
41+
}
42+
43+
std::string ReplaceInCopy(const std::string &org, const std::string &searchStr, const std::string &ReplacementStr)
44+
{
45+
std::string str = org;
2946
ReplaceAll(str, searchStr, ReplacementStr);
3047
return str;
3148
}
49+
50+
51+
void TraceDiagnosticInfo( std::string msg )
52+
{// AfxTrace has a max buffer size of 512 bytes, which is 256 wchar_t's. Need to make sure the diagnostic info doesn't overrun the buffer by sending it MaxSectionSize characters at a time
53+
const int MaxSectionSize = 100;
54+
const int strsize = msg.size();
55+
if ( strsize > MaxSectionSize )
56+
{
57+
Common::Replace( msg, "\n", " " );
58+
Common::Replace( msg, "\r", " " );
59+
}
60+
for ( int i = 0; (i * MaxSectionSize) < strsize; ++i )
61+
AfxTrace( i ? L"\t\t\t\t%S\n" : L"Exception Info:\t%S\n", msg.substr( i * MaxSectionSize, (i + 1) * MaxSectionSize ).c_str() );
62+
}
63+
64+
//Logging::Logging( const char* SoureCode_FileName, int SourceCode_LineNo, const char* SoureCode_FunctionName, Verbosity verbosity, const wchar_t* pszFormat, CString s1 )
65+
//{
66+
// CString strVerbosity;
67+
// switch ( verbosity )
68+
// {
69+
// case DBG:
70+
// strVerbosity = _T( "Debug" );
71+
// break;
72+
// case INF:
73+
// strVerbosity = _T( "Info" );
74+
// break;
75+
// case WRN:
76+
// strVerbosity = _T( "Warn" );
77+
// break;
78+
// case ERR:
79+
// strVerbosity = _T( "Error" );
80+
// break;
81+
// case FATAL:
82+
// strVerbosity = _T( "Fatal-Error" );
83+
// break;
84+
// }
85+
// CString Msg;
86+
// Msg.Format( _T( "%S(%i):%S:\t%s:\t%s" ), SoureCode_FileName, SourceCode_LineNo, SoureCode_FunctionName, strVerbosity.GetBuffer(), pszFormat );
87+
// const wchar_t * msg = Msg.GetBuffer();
88+
// AfxTrace( msg, s1 );
89+
90+
//}
91+
92+
//Logging::Logging( const char* SoureCode_FileName, int SourceCode_LineNo, const char* SoureCode_FunctionName, Verbosity verbosity, const wchar_t* pszFormat, CString s1, CString s2 )
93+
//{
94+
// CString strVerbosity;
95+
// switch ( verbosity )
96+
// {
97+
// case DBG:
98+
// strVerbosity = _T( "Debug" );
99+
// break;
100+
// case INF:
101+
// strVerbosity = _T( "Info" );
102+
// break;
103+
// case WRN:
104+
// strVerbosity = _T( "Warn" );
105+
// break;
106+
// case ERR:
107+
// strVerbosity = _T( "Error" );
108+
// break;
109+
// case FATAL:
110+
// strVerbosity = _T( "Fatal-Error" );
111+
// break;
112+
// }
113+
// CString Msg;
114+
// Msg.Format( _T( "%S(%i):%S:\t%s:\t%s" ), SoureCode_FileName, SourceCode_LineNo, SoureCode_FunctionName, strVerbosity.operator LPCWSTR(), pszFormat );
115+
// AfxTrace( Msg, s1, s2 );
116+
117+
//}
118+
119+
//Logging::Logging( const char* SoureCode_FileName, int SourceCode_LineNo, const char* SoureCode_FunctionName, Verbosity verbosity, const wchar_t* pszFormat, va_list argList )
120+
//{
121+
// CString strVerbosity;
122+
// switch ( verbosity )
123+
// {
124+
// case DBG:
125+
// strVerbosity = _T( "Debug" );
126+
// break;
127+
// case INF:
128+
// strVerbosity = _T( "Info" );
129+
// break;
130+
// case WRN:
131+
// strVerbosity = _T( "Warn" );
132+
// break;
133+
// case ERR:
134+
// strVerbosity = _T( "Error" );
135+
// break;
136+
// case FATAL:
137+
// strVerbosity = _T( "Fatal-Error" );
138+
// break;
139+
// }
140+
// CString Msg;
141+
// Msg.Format(_T( "%S(%i):%S:\t%s:\t%s" ), SoureCode_FileName , SourceCode_LineNo , SoureCode_FunctionName , strVerbosity.operator LPCWSTR(), pszFormat);
142+
// AfxTrace( Msg, argList );
143+
//}
144+
145+
//Logging::Logging( const char* SoureCode_FileName, int SourceCode_LineNo, const char* SoureCode_FunctionName, Verbosity verbosity, const char* pszFormat, va_list argList )
146+
//{
147+
// CString strVerbosity;
148+
// switch ( verbosity )
149+
// {
150+
// case DBG:
151+
// strVerbosity = _T( "Debug" );
152+
// break;
153+
// case INF:
154+
// strVerbosity = _T( "Info" );
155+
// break;
156+
// case WRN:
157+
// strVerbosity = _T( "Warn" );
158+
// break;
159+
// case ERR:
160+
// strVerbosity = _T( "Error" );
161+
// break;
162+
// case FATAL:
163+
// strVerbosity = _T( "Fatal-Error" );
164+
// break;
165+
// }
166+
// CString Msg;
167+
// Msg.Format( _T( "%S(%i):%S:\t%s:\t%S" ), SoureCode_FileName, SourceCode_LineNo, SoureCode_FunctionName, strVerbosity.operator LPCWSTR(), pszFormat );
168+
// AfxTrace( Msg, argList );
169+
//}
170+
171+
//int Logging::GlobalLoggingSettings = Verbosity::WRN | Attrib::TIMEOUT30Sec;
172+
//
173+
//int Logging::GetGlobalLoggingSettings()
174+
//{
175+
// return GlobalLoggingSettings;
176+
//}
177+
178+
//int Logging::AddAttrib( int logattrib )
179+
//{
180+
// GlobalLoggingSettings |= logattrib;
181+
// return GlobalLoggingSettings;
182+
//}
183+
184+
//int Logging::RemoveAttrib( int logattrib )
185+
//{
186+
// GlobalLoggingSettings &= ~(1UL << logattrib);
187+
// return GlobalLoggingSettings;
188+
//}
189+
190+
//int Logging::SetAttrib( int logattrib )
191+
//{
192+
// GlobalLoggingSettings = logattrib;
193+
// return GlobalLoggingSettings;
194+
//}
32195
}
33196

RegexAssistant/CommonFunctions.h

Lines changed: 131 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,57 @@
44
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.
55
*/
66
#pragma once
7-
87
#include <string>
9-
#include <cstring>
8+
#include <memory>
109
#include <mutex>
1110

12-
enum { QISUCCESS = 0};
13-
#define LOGEXT "log"
14-
15-
class auto_lock
16-
{
17-
std::mutex mtx;
18-
public:
19-
auto_lock() { mtx.lock(); }
20-
~auto_lock() { mtx.unlock(); }
21-
};
2211

23-
namespace FXString
12+
namespace Common
2413
{
2514
std::wstring ToWString(std::string src);
2615
inline std::wstring ToWString( const std::wstring &src ) { return src; }
27-
inline std::wstring ToWString( const CString &src) { return src.operator LPCWSTR(); }
28-
29-
inline CString ToTString(const char * src) { return ToWString(src).c_str(); }
30-
inline CString ToTString(const wchar_t * src) { return src; }
16+
inline std::wstring ToWString( const LPCWSTR src ) { return std::wstring( src ); }
3117

3218
std::string ToString( std::wstring src);
3319
inline std::string ToString( const std::string &src ) { return src; }
34-
//inline std::string ToString( const CString &src ) { return ToString( std::wstring(src.operator LPCWSTR()) ); }
20+
inline std::string ToString( const LPCWSTR src ) { return ToString( std::wstring(src) ); }
21+
22+
inline CString ToCString(const char * src) { return ToWString(src).c_str(); }
23+
inline CString ToCString(const wchar_t * src) { return src; }
24+
25+
inline std::string ToString( int src ) { return std::to_string( src ); }
26+
inline std::string ToString( long src ) { return std::to_string( src ); }
27+
inline std::string ToString( long long src ) { return std::to_string( src ); }
28+
inline std::string ToString( unsigned src ) { return std::to_string( src ); }
29+
inline std::string ToString( unsigned long src ) { return std::to_string( src ); }
30+
inline std::string ToString( unsigned long long src ) { return std::to_string( src ); }
31+
inline std::string ToString( float src ) { return std::to_string( src ); }
32+
inline std::string ToString( double src ) { return std::to_string( src ); }
33+
inline std::string ToString( long double src ) { return std::to_string( src ); }
34+
35+
inline std::wstring ToWString( int src ) { return std::to_wstring( src ); }
36+
inline std::wstring ToWString( long src ) { return std::to_wstring( src ); }
37+
inline std::wstring ToWString( long long src ) { return std::to_wstring( src ); }
38+
inline std::wstring ToWString( unsigned src ) { return std::to_wstring( src ); }
39+
inline std::wstring ToWString( unsigned long src ) { return std::to_wstring( src ); }
40+
inline std::wstring ToWString( unsigned long long src ) { return std::to_wstring( src ); }
41+
inline std::wstring ToWString( float src ) { return std::to_wstring( src ); }
42+
inline std::wstring ToWString( double src ) { return std::to_wstring( src ); }
43+
inline std::wstring ToWString( long double src ) { return std::to_wstring( src ); }
44+
45+
inline CString ToCString( int src ) { return std::to_wstring( src ).c_str(); }
46+
inline CString ToCString( long src ) { return std::to_wstring( src ).c_str(); }
47+
inline CString ToCString( long long src ) { return std::to_wstring( src ).c_str(); }
48+
inline CString ToCString( unsigned src ) { return std::to_wstring( src ).c_str(); }
49+
inline CString ToCString( unsigned long src ) { return std::to_wstring( src ).c_str(); }
50+
inline CString ToCString( unsigned long long src ) { return std::to_wstring( src ).c_str(); }
51+
inline CString ToCString( float src ) { return std::to_wstring( src ).c_str(); }
52+
inline CString ToCString( double src ) { return std::to_wstring( src ).c_str(); }
53+
inline CString ToCString( long double src ) { return std::to_wstring( src ).c_str(); }
3554

36-
std::string CopyAndReplaceAll(std::string src, const std::string &searchStr, const std::string &ReplacementStr);
37-
void ReplaceAll(std::string &src, const std::string &searchStr, const std::string &ReplacementStr);
55+
std::string ReplaceInCopy(const std::string &src, const std::string &searchStr, const std::string &ReplacementStr);
56+
std::string Replace(std::string &src, const std::string &searchStr, const std::string &ReplacementStr);
57+
void ReplaceAll( std::string &src, const std::string &searchStr, const std::string &ReplacementStr );
3858

3959
template <class strType1, class strType2> bool MatchesNoCase(strType1 str1, strType2 str2)
4060
{
@@ -50,6 +70,97 @@ namespace FXString
5070
inline DWORD StrDwLen( const char * str ) { return static_cast<DWORD>(strlen( str )); }
5171
inline DWORD StrDwLen( const wchar_t * str ) { return static_cast<DWORD>(wcslen( str )); }
5272
inline DWORD StrDwLen( const CString &str ) { return static_cast<DWORD>(str.GetLength()); }
73+
74+
75+
class errno_exception
76+
{
77+
int m_errno;
78+
std::string m_what;
79+
std::exception *m_exception;
80+
std::string m_name;
81+
public:
82+
errno_exception( const char *name, std::exception &Exception, int no = GetLastError(), std::string s = "" ) :m_errno( no ), m_what( s.size() ? s : Exception.what() ), m_exception( &Exception ), m_name( name ) {}
83+
errno_exception( const char *s = NULL, int no = GetLastError() ) :m_errno( no ), m_what( (s == NULL) ? "Unknown Exception" : s ), m_exception( NULL ), m_name( (s == NULL) ? "Unknown Exception" : "Exception" ) {}
84+
errno_exception( std::string &s, int no = GetLastError() ) :m_errno( no ), m_what( s ), m_exception( NULL ), m_name( "Exception" ) {}
85+
const char* what() { return (m_exception == NULL) ? m_what.c_str() : m_exception->what(); }
86+
int code() { return m_errno; }
87+
const char* name() { return m_name.c_str(); }
88+
};
89+
90+
class auto_lock
91+
{
92+
std::mutex mtx;
93+
public:
94+
auto_lock(){ mtx.lock(); }
95+
~auto_lock(){ mtx.unlock(); }
96+
};
97+
98+
void TraceDiagnosticInfo( std::string msg );
99+
100+
//
101+
// enum Attrib
102+
// {
103+
//#ifdef _DEBUG
104+
// DEBUG_ON = 1 << 31,
105+
//#else
106+
// DEBUG_ON = 0,
107+
//#endif
108+
// ONFIRSTPASS = 1 << 18, // Log, Popup, or trace only on first pass
109+
// LOG_ON_EXIT = 1 << 19, // Postpone logging until exit from scope
110+
//
111+
// LOG_REL = 1 << 26, // Log only in release mode. Use in conjuntion with INF, WRN, ERR, & FATAL
112+
// LOG_DBG = 1 << 27, // Log only in debug mode. Use in conjuntion with INF, WRN, ERR, & FATAL
113+
// POP_REL = 1 << 28, // Popup or Modeless only in release mode
114+
// POP_DBG = 1 << 29, // Popup or Modeless only in debug mode
115+
//
116+
// TIMEOUT10Sec = 10, // Have a 10 second time-out for MODELESS or POPUPT
117+
// TIMEOUT30Sec = 30, // Have a 30 second time-out for MODELESS or POPUPT
118+
// TIMEOUT1Min = 60, // Have a 1 minute time-out for MODELESS or POPUPT
119+
// TIMEOUT2Min = 120, // Have a 2 minutes time-out for MODELESS or POPUPT
120+
// TIMEOUT5Min = 300, // Have a 5 minutes time-out for MODELESS or POPUPT
121+
// TIMEOUT10Min = 600, // Have a 10 minutes time-out for MODELESS or POPUPT
122+
// TIMEOUT15Min = 900, // Have a 15 minutes time-out for MODELESS or POPUPT
123+
//
124+
// };
125+
//
126+
// enum LogType
127+
// {
128+
// TRACEMSG = 1 << 20, // Trace message (only in debug mode)
129+
// LOGMSG = 1 << 21, // Log to a file
130+
// STDCERR = 1 << 22, // Log to std::cerr
131+
// POPUP = 1 << 23, // Call MessageBox with logging details
132+
// MODELESS = 1 << 24, // Create a modeless window that will close automatically via time-out
133+
// POPUPT = 1 << 25, // Call MessageBox which will close automatically via time-out
134+
// };
135+
//
136+
// enum Verbosity
137+
// {
138+
// //Verbosity Level
139+
// OFF = 1 << 12, // Logging off
140+
// DBG = 1 << 13, // Debug logging
141+
// INF = 1 << 14, // Informational logging
142+
// WRN = 1 << 15, // An unexpected result occurred, but the program can continue safely
143+
// ERR = 1 << 16, // An unexpected result occurred, which stops the program from completing a required task
144+
// FATAL = 1 << 17, // An error occurred, in which the program can not continue, and must exit
145+
// };
146+
//
147+
// class Logging
148+
// {
149+
// public:
150+
// Logging( const char* SoureCode_FileName, int SourceCode_LineNo, const char* SoureCode_FunctionName, Verbosity verbosity, const wchar_t* pszFormat, CString s1 );
151+
// Logging( const char* SoureCode_FileName, int SourceCode_LineNo, const char* SoureCode_FunctionName, Verbosity verbosity, const wchar_t* pszFormat, CString s1, CString s2 );
152+
// //Logging( const char* SoureCode_FileName, int SourceCode_LineNo, const char* SoureCode_FunctionName, Verbosity verbosity, const wchar_t* pszFormat, va_list argList );
153+
// //Logging( const char* SoureCode_FileName, int SourceCode_LineNo, const char* SoureCode_FunctionName, Verbosity verbosity, const char* pszFormat, va_list argList );
154+
// static int GetGlobalLoggingSettings();
155+
// static int AddAttrib( int logattrib );
156+
// static int RemoveAttrib( int logattrib );
157+
// static int SetAttrib( int logattrib );
158+
// protected:
159+
// static int GlobalLoggingSettings;
160+
// };
53161
}
54162

163+
#define REPORT_ERR_AND_EXIT(exit_err_no, msg_format, ...) {CString msg; msg.Format(_T("Error: " msg_format " Performming early exit due to error."),__VA_ARGS__);AfxMessageBox(msg);exit(exit_err_no);}
164+
165+
#define ERR_LOG(msg_format, ... ) {Common::Logging logging(__FILE__, __LINE__, __FUNCTION__, Common::Verbosity::ERR, msg_format __VA_OPT__(,) __VA_ARGS__);}
55166

0 commit comments

Comments
 (0)