Index: src/libchcore/TBaseException.cpp =================================================================== diff -u -rc1f7af79a52133c6d4b14944c3370288be7f5af5 -r23ff4021e13382a5e6da1f88e5fe173f2cffc743 --- src/libchcore/TBaseException.cpp (.../TBaseException.cpp) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) +++ src/libchcore/TBaseException.cpp (.../TBaseException.cpp) (revision 23ff4021e13382a5e6da1f88e5fe173f2cffc743) @@ -24,7 +24,7 @@ { TBaseException::TBaseException(EGeneralErrors eErrorCode, const wchar_t* pszMsg, const wchar_t* pszFile, size_t stLineNumber, const wchar_t* pszFunction) : m_eErrorCode(eErrorCode), - m_pszMsg(pszMsg), + m_strMsg(pszMsg ? pszMsg : L""), m_pszFile(pszFile), m_pszFunction(pszFunction), m_stLineNumber(stLineNumber) @@ -39,14 +39,14 @@ void TBaseException::GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const { _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s (error code: %d)"), - m_pszMsg, m_eErrorCode); + m_strMsg.c_str(), m_eErrorCode); pszBuffer[stMaxBuffer - 1] = _T('\0'); } void TBaseException::GetDetailedErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const { _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s\r\nError code: %d\r\nFile: %s\r\nFunction: %s\r\nLine no: %lu"), - m_pszMsg, m_eErrorCode, m_pszFile, m_pszFunction, (unsigned long)m_stLineNumber); + m_strMsg.c_str(), m_eErrorCode, m_pszFile, m_pszFunction, (unsigned long)m_stLineNumber); pszBuffer[stMaxBuffer - 1] = _T('\0'); } } Index: src/libchcore/TBaseException.h =================================================================== diff -u -rc1f7af79a52133c6d4b14944c3370288be7f5af5 -r23ff4021e13382a5e6da1f88e5fe173f2cffc743 --- src/libchcore/TBaseException.h (.../TBaseException.h) (revision c1f7af79a52133c6d4b14944c3370288be7f5af5) +++ src/libchcore/TBaseException.h (.../TBaseException.h) (revision 23ff4021e13382a5e6da1f88e5fe173f2cffc743) @@ -51,7 +51,10 @@ EGeneralErrors m_eErrorCode; // where it happened? - const wchar_t* m_pszMsg; +#pragma warning(push) +#pragma warning(disable: 4251) + std::wstring m_strMsg; +#pragma warning(pop) const wchar_t* m_pszFile; const wchar_t* m_pszFunction; Index: src/libchcore/TCoreWin32Exception.cpp =================================================================== diff -u -ra4635addad389b9e117679437a3e1b64a739ea96 -r23ff4021e13382a5e6da1f88e5fe173f2cffc743 --- src/libchcore/TCoreWin32Exception.cpp (.../TCoreWin32Exception.cpp) (revision a4635addad389b9e117679437a3e1b64a739ea96) +++ src/libchcore/TCoreWin32Exception.cpp (.../TCoreWin32Exception.cpp) (revision 23ff4021e13382a5e6da1f88e5fe173f2cffc743) @@ -48,13 +48,13 @@ // ============================================================================ void TCoreWin32Exception::GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const { - _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s (error code: %d, win32 error code: %lu)"), m_pszMsg, m_eErrorCode, m_dwWin32ErrorCode); + _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s (error code: %d, win32 error code: %lu)"), m_strMsg.c_str(), m_eErrorCode, m_dwWin32ErrorCode); pszBuffer[stMaxBuffer - 1] = _T('\0'); } void TCoreWin32Exception::GetDetailedErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const { - _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s\r\nError code: %d\r\nWin32 error code: %lu\r\nFile: %s\r\nFunction: %s\r\nLine no: %lu"), m_pszMsg, m_eErrorCode, m_dwWin32ErrorCode, m_pszFile, m_pszFunction, (unsigned long)m_stLineNumber); + _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s\r\nError code: %d\r\nWin32 error code: %lu\r\nFile: %s\r\nFunction: %s\r\nLine no: %lu"), m_strMsg.c_str(), m_eErrorCode, m_dwWin32ErrorCode, m_pszFile, m_pszFunction, (unsigned long)m_stLineNumber); pszBuffer[stMaxBuffer - 1] = _T('\0'); } } Index: src/libchcore/TStringPattern.cpp =================================================================== diff -u -r0951d2ccccffb16bd12dad494e561349da17c927 -r23ff4021e13382a5e6da1f88e5fe173f2cffc743 --- src/libchcore/TStringPattern.cpp (.../TStringPattern.cpp) (revision 0951d2ccccffb16bd12dad494e561349da17c927) +++ src/libchcore/TStringPattern.cpp (.../TStringPattern.cpp) (revision 23ff4021e13382a5e6da1f88e5fe173f2cffc743) @@ -21,20 +21,14 @@ #include #include #include +#include +#include +#include "TCoreException.h" using namespace string; namespace chcore { - namespace - { - bool _tcicmp(TCHAR c1, TCHAR c2) - { - TCHAR ch1[2] = { c1, 0 }, ch2[2] = { c2, 0 }; - return (_tcsicmp(ch1, ch2) == 0); - } - } - TStringPattern::TStringPattern() : m_ePatternType(EPatternType::eType_FilenameWildcard) { @@ -124,51 +118,63 @@ bool TStringPattern::Matches(const TSmartPath& pathToMatch) const { - switch(m_ePatternType) + try { - case EPatternType::eType_FilenameWildcard: - { - if(m_strPattern == L"*" || m_strPattern == L"*.*") - return true; + switch(m_ePatternType) + { + case EPatternType::eType_FilenameWildcard: + { + if(m_strPattern == L"*" || m_strPattern == L"*.*") + return true; - std::wstring strPattern = ConvertGlobToRegex(); + std::wstring strPattern = ConvertGlobToRegex(); - std::wstring strText(pathToMatch.GetFileName().ToString()); - std::wregex pattern(strPattern, std::regex_constants::icase | std::regex_constants::ECMAScript); + std::wstring strText(pathToMatch.GetFileName().ToString()); + std::wregex pattern(strPattern, std::regex_constants::icase | std::regex_constants::ECMAScript); - return std::regex_match(strText, pattern); - } + return std::regex_match(strText, pattern); + } - case EPatternType::eType_FullPathWildcard: - { - if(m_strPattern == L"*" || m_strPattern == L"*.*") - return true; + case EPatternType::eType_FullPathWildcard: + { + if(m_strPattern == L"*" || m_strPattern == L"*.*") + return true; - std::wstring strPattern = ConvertGlobToRegex(); - std::wstring strText(pathToMatch.ToString()); - std::wregex pattern(strPattern, std::regex_constants::icase | std::regex_constants::ECMAScript); + std::wstring strPattern = ConvertGlobToRegex(); + std::wstring strText(pathToMatch.ToString()); + std::wregex pattern(strPattern, std::regex_constants::icase | std::regex_constants::ECMAScript); - return std::regex_match(strText, pattern); - } + return std::regex_match(strText, pattern); + } - case EPatternType::eType_FilenameRegex: - { - std::wstring strText(pathToMatch.GetFileName().ToString()); - std::wregex pattern(m_strPattern.c_str(), std::regex::icase | std::regex::ECMAScript | std::regex::collate); + case EPatternType::eType_FilenameRegex: + { + std::wstring strText(pathToMatch.GetFileName().ToString()); + std::wregex pattern(m_strPattern.c_str(), std::regex::icase | std::regex::ECMAScript | std::regex::collate); - return std::regex_match(strText, pattern); - } + return std::regex_match(strText, pattern); + } - case EPatternType::eType_FullPathRegex: - { - std::wstring strText(pathToMatch.ToString()); - std::wregex pattern(m_strPattern.c_str(), std::regex::icase | std::regex::ECMAScript | std::regex::collate); + case EPatternType::eType_FullPathRegex: + { + std::wstring strText(pathToMatch.ToString()); + std::wregex pattern(m_strPattern.c_str(), std::regex::icase | std::regex::ECMAScript | std::regex::collate); - return std::regex_match(strText, pattern); + return std::regex_match(strText, pattern); + } + + default: + throw std::invalid_argument("Unsupported pattern type"); + } } + catch(const std::regex_error& e) + { + TString strErr = L"Regular expression processing error.\nExpression: " + m_strPattern + L"\nError: "; + ATL::CA2W ca2w(e.what()); - default: - throw std::invalid_argument("Unsupported pattern type"); + strErr += ca2w; + + throw TCoreException(eErr_InvalidData, strErr.c_str(), LOCATION); } } Index: src/libchengine/TFileException.cpp =================================================================== diff -u -r33b33baa373533d0cff8ea5d25154b370f2b2e05 -r23ff4021e13382a5e6da1f88e5fe173f2cffc743 --- src/libchengine/TFileException.cpp (.../TFileException.cpp) (revision 33b33baa373533d0cff8ea5d25154b370f2b2e05) +++ src/libchengine/TFileException.cpp (.../TFileException.cpp) (revision 23ff4021e13382a5e6da1f88e5fe173f2cffc743) @@ -30,14 +30,14 @@ void TFileException::GetErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const { - _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s (error code: %d, win32 error code: %lu, path: %s)"), m_pszMsg, m_eErrorCode, m_dwNativeErrorCode, m_path.ToString()); + _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s (error code: %d, win32 error code: %lu, path: %s)"), m_strMsg.c_str(), m_eErrorCode, m_dwNativeErrorCode, m_path.ToString()); pszBuffer[stMaxBuffer - 1] = _T('\0'); } void TFileException::GetDetailedErrorInfo(wchar_t* pszBuffer, size_t stMaxBuffer) const { _snwprintf_s(pszBuffer, stMaxBuffer, _TRUNCATE, _T("%s\r\nError code: %d\r\nWin32 error code: %lu\r\nFile: %s\r\nSource file: %s\r\nFunction: %s\r\nLine no: %lu"), - m_pszMsg, m_eErrorCode, m_dwNativeErrorCode, m_path.ToString(), m_pszFile, m_pszFunction, (unsigned long)m_stLineNumber); + m_strMsg.c_str(), m_eErrorCode, m_dwNativeErrorCode, m_path.ToString(), m_pszFile, m_pszFunction, (unsigned long)m_stLineNumber); pszBuffer[stMaxBuffer - 1] = _T('\0'); } }