From 247bf8ac0aa3ba2e6187ff96b1b91b80b153d94b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 29 Mar 2015 16:18:53 +0000 Subject: CMString::Detouch() - handy way to obtain a buffer compatible with mir_free() git-svn-id: http://svn.miranda-ng.org/main/trunk@12541 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- bin10/lib/mir_core.lib | Bin 328086 -> 328854 bytes bin10/lib/mir_core64.lib | Bin 329818 -> 330606 bytes bin12/lib/mir_core.lib | Bin 328086 -> 328854 bytes bin12/lib/mir_core64.lib | Bin 329818 -> 330606 bytes include/m_string.h | 68 +++++++++++++++++++++++----------------- include/m_string.inl | 7 +++++ src/mir_core/src/mir_core.def | 2 ++ src/mir_core/src/mir_core64.def | 2 ++ 8 files changed, 51 insertions(+), 28 deletions(-) diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib index 1b66d13388..1ef1953f0a 100644 Binary files a/bin10/lib/mir_core.lib and b/bin10/lib/mir_core.lib differ diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib index 751cc7e5f9..ec2123d9b7 100644 Binary files a/bin10/lib/mir_core64.lib and b/bin10/lib/mir_core64.lib differ diff --git a/bin12/lib/mir_core.lib b/bin12/lib/mir_core.lib index bf921fdb39..96a6b7b310 100644 Binary files a/bin12/lib/mir_core.lib and b/bin12/lib/mir_core.lib differ diff --git a/bin12/lib/mir_core64.lib b/bin12/lib/mir_core64.lib index 8205621e8e..a6c5922548 100644 Binary files a/bin12/lib/mir_core64.lib and b/bin12/lib/mir_core64.lib differ diff --git a/include/m_string.h b/include/m_string.h index 6d152e7b9c..3e03ad2ba8 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -271,12 +271,12 @@ private: template< typename _CharType = char > -class ChTraitsCRT : public ChTraitsBase< _CharType > +class ChTraitsCRT : public ChTraitsBase < _CharType > { public: static char* __stdcall CharNext(const char* p) { - return reinterpret_cast< char* >(_mbsinc(reinterpret_cast< const unsigned char* >(p))); + return reinterpret_cast(_mbsinc(reinterpret_cast(p))); } static int __stdcall IsDigit(char ch) @@ -291,59 +291,59 @@ public: static int __stdcall StringCompare(LPCSTR pszA, LPCSTR pszB) { - return _mbscmp(reinterpret_cast< const unsigned char* >(pszA), reinterpret_cast< const unsigned char* >(pszB)); + return _mbscmp(reinterpret_cast(pszA), reinterpret_cast(pszB)); } static int __stdcall StringCompareIgnore(LPCSTR pszA, LPCSTR pszB) { - return _mbsicmp(reinterpret_cast< const unsigned char* >(pszA), reinterpret_cast< const unsigned char* >(pszB)); + return _mbsicmp(reinterpret_cast(pszA), reinterpret_cast(pszB)); } static int __stdcall StringCollate(LPCSTR pszA, LPCSTR pszB) { - return _mbscoll(reinterpret_cast< const unsigned char* >(pszA), reinterpret_cast< const unsigned char* >(pszB)); + return _mbscoll(reinterpret_cast(pszA), reinterpret_cast(pszB)); } static int __stdcall StringCollateIgnore(LPCSTR pszA, LPCSTR pszB) { - return _mbsicoll(reinterpret_cast< const unsigned char* >(pszA), reinterpret_cast< const unsigned char* >(pszB)); + return _mbsicoll(reinterpret_cast(pszA), reinterpret_cast(pszB)); } static LPCSTR __stdcall StringFindString(LPCSTR pszBlock, LPCSTR pszMatch) { - return reinterpret_cast< LPCSTR >(_mbsstr(reinterpret_cast< const unsigned char* >(pszBlock), - reinterpret_cast< const unsigned char* >(pszMatch))); + return reinterpret_cast(_mbsstr(reinterpret_cast(pszBlock), + reinterpret_cast(pszMatch))); } static LPSTR __stdcall StringFindString(LPSTR pszBlock, LPCSTR pszMatch) { - return const_cast< LPSTR >(StringFindString(const_cast< LPCSTR >(pszBlock), pszMatch)); + return const_cast(StringFindString(const_cast(pszBlock), pszMatch)); } static LPCSTR __stdcall StringFindChar(LPCSTR pszBlock, char chMatch) { - return reinterpret_cast< LPCSTR >(_mbschr(reinterpret_cast< const unsigned char* >(pszBlock), (unsigned char)chMatch)); + return reinterpret_cast(_mbschr(reinterpret_cast(pszBlock), (unsigned char)chMatch)); } static LPCSTR __stdcall StringFindCharRev(LPCSTR psz, char ch) { - return reinterpret_cast< LPCSTR >(_mbsrchr(reinterpret_cast< const unsigned char* >(psz), (unsigned char)ch)); + return reinterpret_cast(_mbsrchr(reinterpret_cast(psz), (unsigned char)ch)); } static LPCSTR __stdcall StringScanSet(LPCSTR pszBlock, LPCSTR pszMatch) { - return reinterpret_cast< LPCSTR >(_mbspbrk(reinterpret_cast< const unsigned char* >(pszBlock), - reinterpret_cast< const unsigned char* >(pszMatch))); + return reinterpret_cast(_mbspbrk(reinterpret_cast(pszBlock), + reinterpret_cast(pszMatch))); } static int __stdcall StringSpanIncluding(LPCSTR pszBlock, LPCSTR pszSet) { - return (int)_mbsspn(reinterpret_cast< const unsigned char* >(pszBlock), reinterpret_cast< const unsigned char* >(pszSet)); + return (int)_mbsspn(reinterpret_cast(pszBlock), reinterpret_cast(pszSet)); } static int __stdcall StringSpanExcluding(LPCSTR pszBlock, LPCSTR pszSet) { - return (int)_mbscspn(reinterpret_cast< const unsigned char* >(pszBlock), reinterpret_cast< const unsigned char* >(pszSet)); + return (int)_mbscspn(reinterpret_cast(pszBlock), reinterpret_cast(pszSet)); } static LPSTR __stdcall StringUppercase(LPSTR psz) @@ -372,7 +372,7 @@ public: static LPSTR __stdcall StringReverse(LPSTR psz) { - return reinterpret_cast< LPSTR >(_mbsrev(reinterpret_cast< unsigned char* >(psz))); + return reinterpret_cast(_mbsrev(reinterpret_cast(psz))); } static int __stdcall GetFormattedLength(LPCSTR pszFormat, va_list args) @@ -401,7 +401,7 @@ public: static int __stdcall GetBaseTypeLength(LPCWSTR pszSource) { // Returns required buffer length in XCHARs - return ::WideCharToMultiByte(Langpack_GetDefaultCodePage(), 0, pszSource, -1, NULL, 0, NULL, NULL)-1; + return ::WideCharToMultiByte(Langpack_GetDefaultCodePage(), 0, pszSource, -1, NULL, 0, NULL, NULL) - 1; } static int __stdcall GetBaseTypeLength(LPCWSTR pszSource, int nLength) @@ -412,7 +412,7 @@ public: static void __stdcall ConvertToBaseType(LPSTR pszDest, int nDestLength, LPCSTR pszSrc, int nSrcLength = -1) { - if (nSrcLength == -1) { nSrcLength=1 + GetBaseTypeLength(pszSrc); } + if (nSrcLength == -1) { nSrcLength = 1 + GetBaseTypeLength(pszSrc); } // nLen is in XCHARs memcpy_s(pszDest, nDestLength*sizeof(char), pszSrc, nSrcLength*sizeof(char)); } @@ -425,31 +425,30 @@ public: static void ConvertToOem(_CharType* pstrString) { - BOOL fSuccess=::CharToOemA(pstrString, pstrString); + BOOL fSuccess = ::CharToOemA(pstrString, pstrString); } static void ConvertToAnsi(_CharType* pstrString) { - BOOL fSuccess=::OemToCharA(pstrString, pstrString); + BOOL fSuccess = ::OemToCharA(pstrString, pstrString); } static void ConvertToOem(_CharType* pstrString, size_t size) { - if (size>UINT_MAX) - { + if (size > UINT_MAX) { return; } - DWORD dwSize=static_cast(size); - BOOL fSuccess=::CharToOemBuffA(pstrString, pstrString, dwSize); + DWORD dwSize = static_cast(size); + BOOL fSuccess = ::CharToOemBuffA(pstrString, pstrString, dwSize); } static void ConvertToAnsi(_CharType* pstrString, size_t size) { - if (size>UINT_MAX) + if (size > UINT_MAX) return; - DWORD dwSize=static_cast(size); - BOOL fSuccess=::OemToCharBuffA(pstrString, pstrString, dwSize); + DWORD dwSize = static_cast(size); + BOOL fSuccess = ::OemToCharBuffA(pstrString, pstrString, dwSize); } static void __stdcall FloodCharacters(char ch, int nLength, char* pch) @@ -499,13 +498,18 @@ public: static int __stdcall GetCharLen(const char* pch) { // returns char length - return int(_mbclen(reinterpret_cast< const unsigned char* >(pch))); + return int(_mbclen(reinterpret_cast(pch))); } static DWORD __stdcall GetEnvironmentVariable(LPCSTR pszVar, LPSTR pszBuffer, DWORD dwSize) { return ::GetEnvironmentVariableA(pszVar, pszBuffer, dwSize); } + + static char* MirCopy(const char *pstrString, size_t size) + { + return mir_strndup(pstrString, size); + } }; // specialization for wchar_t @@ -741,6 +745,11 @@ public: static void __stdcall ConvertToAnsi(LPWSTR /*psz*/, size_t) { } + + static LPWSTR MirCopy(LPCWSTR pstrString, size_t size) + { + return mir_wstrndup(pstrString, size); + } }; template< typename BaseType, class StringTraits > @@ -913,6 +922,9 @@ public: PCXSTR AppendFormat(PCXSTR pszFormat, ...); void AppendFormatV(PCXSTR pszFormat, va_list args); + // return a copy of string to be freed by mir_free() + PXSTR Detouch() const; + // OLE BSTR support // allocate a BSTR containing a copy of the string diff --git a/include/m_string.inl b/include/m_string.inl index b42bc3b99b..4615319416 100644 --- a/include/m_string.inl +++ b/include/m_string.inl @@ -1411,6 +1411,13 @@ BOOL CMStringT::GetEnvironmentVariable(PCXSTR pszVar) return bRetVal; } +// Set the string to the value of environment variable 'pszVar' +template< typename BaseType, class StringTraits > +typename CMStringT::PXSTR CMStringT::Detouch() const +{ + return StringTraits::MirCopy(CMStringT::GetString(), GetLength()); +} + ///////////////////////////////////////////////////////////////////////////////////////// template< typename BaseType, class StringTraits > diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index d43ffd571c..d2c5cfb803 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1076,3 +1076,5 @@ ProtoWindowAdd @1073 ProtoWindowRemove @1074 Proto_IsProtocolLoaded @1075 Proto_RegisterModule @1076 +?Detouch@?$CMStringT@DV?$ChTraitsCRT@D@@@@QBEPADXZ @1077 NONAME +?Detouch@?$CMStringT@_WV?$ChTraitsCRT@_W@@@@QBEPA_WXZ @1078 NONAME diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index b281f47266..092c1e47b4 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1076,3 +1076,5 @@ ProtoWindowAdd @1073 ProtoWindowRemove @1074 Proto_IsProtocolLoaded @1075 Proto_RegisterModule @1076 +?Detouch@?$CMStringT@DV?$ChTraitsCRT@D@@@@QEBAPEADXZ @1077 NONAME +?Detouch@?$CMStringT@_WV?$ChTraitsCRT@_W@@@@QEBAPEA_WXZ @1078 NONAME -- cgit v1.2.3