diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2008-08-19 04:00:00 +0400 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:15:57 +0300 |
commit | c10e6b16f6d5484ed896b2c614cb7fb77f336d24 (patch) | |
tree | f7a2ac132f883d95c2cf28ab01d58963de1ee811 /CPP/Common | |
parent | 173c07e166fdf6fcd20f18ea73008f1b628945df (diff) |
4.60 beta
Diffstat (limited to 'CPP/Common')
-rwxr-xr-x | CPP/Common/Buffer.h | 4 | ||||
-rwxr-xr-x | CPP/Common/C_FileIO.cpp | 2 | ||||
-rwxr-xr-x | CPP/Common/CommandLineParser.cpp | 14 | ||||
-rwxr-xr-x | CPP/Common/DynamicBuffer.h | 2 | ||||
-rwxr-xr-x | CPP/Common/IntToString.cpp | 4 | ||||
-rwxr-xr-x | CPP/Common/ListFileUtils.cpp | 2 | ||||
-rwxr-xr-x | CPP/Common/MyCom.h | 23 | ||||
-rwxr-xr-x | CPP/Common/MyString.h | 16 | ||||
-rwxr-xr-x | CPP/Common/MyVector.h | 10 | ||||
-rwxr-xr-x | CPP/Common/MyWindows.cpp | 12 | ||||
-rwxr-xr-x | CPP/Common/StdInStream.cpp | 10 | ||||
-rwxr-xr-x | CPP/Common/StdOutStream.cpp | 2 | ||||
-rwxr-xr-x | CPP/Common/StringConvert.cpp | 10 | ||||
-rwxr-xr-x | CPP/Common/Wildcard.cpp | 14 |
14 files changed, 64 insertions, 61 deletions
diff --git a/CPP/Common/Buffer.h b/CPP/Common/Buffer.h index cc8b3428..b6960fa8 100755 --- a/CPP/Common/Buffer.h +++ b/CPP/Common/Buffer.h @@ -32,7 +32,7 @@ public: if (newCapacity > 0) { newBuffer = new T[newCapacity]; - if(_capacity > 0) + if (_capacity > 0) memmove(newBuffer, _items, MyMin(_capacity, newCapacity) * sizeof(T)); } else @@ -44,7 +44,7 @@ public: CBuffer& operator=(const CBuffer &buffer) { Free(); - if(buffer._capacity > 0) + if (buffer._capacity > 0) { SetCapacity(buffer._capacity); memmove(_items, buffer._items, buffer._capacity * sizeof(T)); diff --git a/CPP/Common/C_FileIO.cpp b/CPP/Common/C_FileIO.cpp index 3c7f82d9..b4893d65 100755 --- a/CPP/Common/C_FileIO.cpp +++ b/CPP/Common/C_FileIO.cpp @@ -21,7 +21,7 @@ bool CFileBase::OpenBinary(const char *name, int flags) bool CFileBase::Close() { - if(_handle == -1) + if (_handle == -1) return true; if (close(_handle) != 0) return false; diff --git a/CPP/Common/CommandLineParser.cpp b/CPP/Common/CommandLineParser.cpp index 52785d07..6de5e63b 100755 --- a/CPP/Common/CommandLineParser.cpp +++ b/CPP/Common/CommandLineParser.cpp @@ -99,14 +99,14 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) int pos = 0; if (!IsItSwitchChar(s[pos])) return false; - while(pos < len) + while (pos < len) { if (IsItSwitchChar(s[pos])) pos++; const int kNoLen = -1; int matchedSwitchIndex = 0; // GCC Warning int maxLen = kNoLen; - for(int switchIndex = 0; switchIndex < _numSwitches; switchIndex++) + for (int switchIndex = 0; switchIndex < _numSwitches; switchIndex++) { int switchLen = MyStringLen(switchForms[switchIndex].IDString); if (switchLen <= maxLen || pos + switchLen > len) @@ -114,8 +114,8 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) UString temp = s + pos; temp = temp.Left(switchLen); - if(temp.CompareNoCase(switchForms[switchIndex].IDString) == 0) - // if(_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0) + if (temp.CompareNoCase(switchForms[switchIndex].IDString) == 0) + // if (_strnicmp(switchForms[switchIndex].IDString, LPCSTR(s) + pos, switchLen) == 0) { matchedSwitchIndex = switchIndex; maxLen = switchLen; @@ -180,7 +180,7 @@ bool CParser::ParseString(const UString &s, const CSwitchForm *switchForms) int maxLen = switchForm.MaxLen; UString stringSwitch = s.Mid(pos, minLen); pos += minLen; - for(int i = minLen; i < maxLen && pos < len; i++, pos++) + for (int i = minLen; i < maxLen && pos < len; i++, pos++) { wchar_t c = s[pos]; if (IsItSwitchChar(c)) @@ -208,12 +208,12 @@ const CSwitchResult& CParser::operator[](size_t index) const int ParseCommand(int numCommandForms, const CCommandForm *commandForms, const UString &commandString, UString &postString) { - for(int i = 0; i < numCommandForms; i++) + for (int i = 0; i < numCommandForms; i++) { const UString id = commandForms[i].IDString; if (commandForms[i].PostStringMode) { - if(commandString.Find(id) == 0) + if (commandString.Find(id) == 0) { postString = commandString.Mid(id.Length()); return i; diff --git a/CPP/Common/DynamicBuffer.h b/CPP/Common/DynamicBuffer.h index 9bdbaac8..fd33cec3 100755 --- a/CPP/Common/DynamicBuffer.h +++ b/CPP/Common/DynamicBuffer.h @@ -26,7 +26,7 @@ public: CDynamicBuffer& operator=(const CDynamicBuffer &buffer) { this->Free(); - if(buffer._capacity > 0) + if (buffer._capacity > 0) { SetCapacity(buffer._capacity); memmove(this->_items, buffer._items, buffer._capacity * sizeof(T)); diff --git a/CPP/Common/IntToString.cpp b/CPP/Common/IntToString.cpp index c071daef..beda203d 100755 --- a/CPP/Common/IntToString.cpp +++ b/CPP/Common/IntToString.cpp @@ -22,7 +22,7 @@ void ConvertUInt64ToString(UInt64 value, char *s, UInt32 base) while (value != 0); do *s++ = temp[--pos]; - while(pos > 0); + while (pos > 0); *s = '\0'; } @@ -38,7 +38,7 @@ void ConvertUInt64ToString(UInt64 value, wchar_t *s) while (value != 0); do *s++ = temp[--pos]; - while(pos > 0); + while (pos > 0); *s = L'\0'; } diff --git a/CPP/Common/ListFileUtils.cpp b/CPP/Common/ListFileUtils.cpp index cf03d324..c1c682a2 100755 --- a/CPP/Common/ListFileUtils.cpp +++ b/CPP/Common/ListFileUtils.cpp @@ -53,7 +53,7 @@ bool ReadNamesFromListFile(LPCWSTR fileName, UStringVector &resultStrings, UINT } UString t; - for(int i = 0; i < u.Length(); i++) + for (int i = 0; i < u.Length(); i++) { wchar_t c = u[i]; if (c == L'\n' || c == 0xD) diff --git a/CPP/Common/MyCom.h b/CPP/Common/MyCom.h index 2cd09358..2f00c258 100755 --- a/CPP/Common/MyCom.h +++ b/CPP/Common/MyCom.h @@ -6,7 +6,7 @@ #include "MyWindows.h" #ifndef RINOK -#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; } +#define RINOK(x) { HRESULT __result_ = (x); if (__result_ != S_OK) return __result_; } #endif template <class T> @@ -78,12 +78,18 @@ public: ////////////////////////////////////////////////////////// +inline HRESULT StringToBstr(LPCOLESTR src, BSTR *bstr) +{ + *bstr = ::SysAllocString(src); + return (*bstr != 0) ? S_OK : E_OUTOFMEMORY; +} + class CMyComBSTR { public: BSTR m_str; - CMyComBSTR() { m_str = NULL; } - CMyComBSTR(LPCOLESTR pSrc) { m_str = ::SysAllocString(pSrc); } + CMyComBSTR(): m_str(NULL) {} + CMyComBSTR(LPCOLESTR src) { m_str = ::SysAllocString(src); } // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); } // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize); } CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); } @@ -107,10 +113,10 @@ public: } return *this; } - CMyComBSTR& operator=(LPCOLESTR pSrc) + CMyComBSTR& operator=(LPCOLESTR src) { ::SysFreeString(m_str); - m_str = ::SysAllocString(pSrc); + m_str = ::SysAllocString(src); return *this; } unsigned int Length() const { return ::SysStringLen(m_str); } @@ -120,16 +126,18 @@ public: { int byteLen = ::SysStringByteLen(m_str); BSTR res = ::SysAllocStringByteLen(NULL, byteLen); - memmove(res, m_str, byteLen); + memcpy(res, m_str, byteLen); return res; } - void Attach(BSTR src) { m_str = src; } + /* + void Attach(BSTR src) { m_str = src; } BSTR Detach() { BSTR s = m_str; m_str = NULL; return s; } + */ void Empty() { ::SysFreeString(m_str); @@ -138,7 +146,6 @@ public: bool operator!() const { return (m_str == NULL); } }; - ////////////////////////////////////////////////////////// class CMyUnknownImp diff --git a/CPP/Common/MyString.h b/CPP/Common/MyString.h index 64095771..82b97618 100755 --- a/CPP/Common/MyString.h +++ b/CPP/Common/MyString.h @@ -24,7 +24,7 @@ template <class T> inline T * MyStringCopy(T *dest, const T *src) { T *destStart = dest; - while((*dest++ = *src++) != 0); + while ((*dest++ = *src++) != 0); return destStart; } @@ -131,7 +131,7 @@ class CStringBase pLast = NULL; p = GetNextCharPointer(p); } - if(pLast != NULL) + if (pLast != NULL) { int i = (int)(pLast - _chars); Delete(i, _length - i); @@ -172,7 +172,7 @@ protected: /* const int kMaxStringSize = 0x20000000; #ifndef _WIN32_WCE - if(newCapacity > kMaxStringSize || newCapacity < _length) + if (newCapacity > kMaxStringSize || newCapacity < _length) throw 1052337; #endif */ @@ -250,7 +250,7 @@ public: { /* #ifndef _WIN32_WCE - if(newLength >= _capacity) + if (newLength >= _capacity) throw 282217; #endif */ @@ -278,7 +278,7 @@ public: } CStringBase& operator=(const CStringBase& s) { - if(&s == this) + if (&s == this) return *this; Empty(); SetCapacity(s._length); @@ -414,7 +414,7 @@ public: } int FindOneOf(const CStringBase &s) const { - for(int i = 0; i < _length; i++) + for (int i = 0; i < _length; i++) if (s.Find(_chars[i]) >= 0) return i; return -1; @@ -461,7 +461,7 @@ public: pLast = NULL; p = GetNextCharPointer(p); } - if(pLast != NULL) + if (pLast != NULL) { int i = pLast - _chars; Delete(i, _length - i); @@ -487,7 +487,7 @@ public: return _length; int numInsertChars = s.Length(); InsertSpace(index, numInsertChars); - for(int i = 0; i < numInsertChars; i++) + for (int i = 0; i < numInsertChars; i++) _chars[index + i] = s[i]; _length += numInsertChars; return _length; diff --git a/CPP/Common/MyVector.h b/CPP/Common/MyVector.h index 0ab79d6e..079e8ae4 100755 --- a/CPP/Common/MyVector.h +++ b/CPP/Common/MyVector.h @@ -47,7 +47,7 @@ public: { int size = v.Size(); Reserve(Size() + size); - for(int i = 0; i < size; i++) + for (int i = 0; i < size; i++) Add(v[i]); return *this; } @@ -141,7 +141,7 @@ public: int i = size / 2; do SortRefDown(p, i, size, compare, param); - while(--i != 0); + while (--i != 0); } do { @@ -176,7 +176,7 @@ public: { int size = v.Size(); Reserve(Size() + size); - for(int i = 0; i < size; i++) + for (int i = 0; i < size; i++) Add(v[i]); return *this; } @@ -191,13 +191,13 @@ public: virtual void Delete(int index, int num = 1) { TestIndexAndCorrectNum(index, num); - for(int i = 0; i < num; i++) + for (int i = 0; i < num; i++) delete (T *)(((void **)_items)[index + i]); CPointerVector::Delete(index, num); } int Find(const T& item) const { - for(int i = 0; i < Size(); i++) + for (int i = 0; i < Size(); i++) if (item == (*this)[i]) return i; return -1; diff --git a/CPP/Common/MyWindows.cpp b/CPP/Common/MyWindows.cpp index d9d8327b..1283946c 100755 --- a/CPP/Common/MyWindows.cpp +++ b/CPP/Common/MyWindows.cpp @@ -94,14 +94,10 @@ HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src) LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2) { - if(ft1->dwHighDateTime < ft2->dwHighDateTime) - return -1; - if(ft1->dwHighDateTime > ft2->dwHighDateTime) - return 1; - if(ft1->dwLowDateTime < ft2->dwLowDateTime) - return -1; - if(ft1->dwLowDateTime > ft2->dwLowDateTime) - return 1; + if (ft1->dwHighDateTime < ft2->dwHighDateTime) return -1; + if (ft1->dwHighDateTime > ft2->dwHighDateTime) return 1; + if (ft1->dwLowDateTime < ft2->dwLowDateTime) return -1; + if (ft1->dwLowDateTime > ft2->dwLowDateTime) return 1; return 0; } diff --git a/CPP/Common/StdInStream.cpp b/CPP/Common/StdInStream.cpp index 65aa8dde..b3d00920 100755 --- a/CPP/Common/StdInStream.cpp +++ b/CPP/Common/StdInStream.cpp @@ -31,7 +31,7 @@ bool CStdInStream::Open(LPCTSTR fileName) bool CStdInStream::Close() { - if(!_streamIsOpen) + if (!_streamIsOpen) return true; _streamIsOpen = (fclose(_stream) != 0); return !_streamIsOpen; @@ -48,12 +48,12 @@ AString CStdInStream::ScanStringUntilNewLine() for (;;) { int intChar = GetChar(); - if(intChar == EOF) + if (intChar == EOF) throw kEOFMessage; char c = char(intChar); if (c == kIllegalChar) throw kIllegalCharMessage; - if(c == kNewLineChar) + if (c == kNewLineChar) break; s += c; } @@ -64,7 +64,7 @@ void CStdInStream::ReadToString(AString &resultString) { resultString.Empty(); int c; - while((c = GetChar()) != EOF) + while ((c = GetChar()) != EOF) resultString += char(c); } @@ -76,7 +76,7 @@ bool CStdInStream::Eof() int CStdInStream::GetChar() { int c = fgetc(_stream); // getc() doesn't work in BeOS? - if(c == EOF && !Eof()) + if (c == EOF && !Eof()) throw kReadErrorMessage; return c; } diff --git a/CPP/Common/StdOutStream.cpp b/CPP/Common/StdOutStream.cpp index 084ee95a..b93e255f 100755 --- a/CPP/Common/StdOutStream.cpp +++ b/CPP/Common/StdOutStream.cpp @@ -30,7 +30,7 @@ bool CStdOutStream::Open(const char *fileName) bool CStdOutStream::Close() { - if(!_streamIsOpen) + if (!_streamIsOpen) return true; if (fclose(_stream) != 0) return false; diff --git a/CPP/Common/StringConvert.cpp b/CPP/Common/StringConvert.cpp index cb57467b..9bd47deb 100755 --- a/CPP/Common/StringConvert.cpp +++ b/CPP/Common/StringConvert.cpp @@ -12,13 +12,13 @@ UString MultiByteToUnicodeString(const AString &srcString, UINT codePage) { UString resultString; - if(!srcString.IsEmpty()) + if (!srcString.IsEmpty()) { int numChars = MultiByteToWideChar(codePage, 0, srcString, srcString.Length(), resultString.GetBuffer(srcString.Length()), srcString.Length() + 1); #ifndef _WIN32_WCE - if(numChars == 0) + if (numChars == 0) throw 282228; #endif resultString.ReleaseBuffer(numChars); @@ -39,7 +39,7 @@ AString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultCh &defaultChar, &defUsed); defaultCharWasUsed = (defUsed != FALSE); #ifndef _WIN32_WCE - if(numChars == 0) + if (numChars == 0) throw 282229; #endif dest.ReleaseBuffer(numChars); @@ -71,7 +71,7 @@ UString MultiByteToUnicodeString(const AString &srcString, UINT codePage) for (int i = 0; i < srcString.Length(); i++) resultString += wchar_t(srcString[i]); /* - if(!srcString.IsEmpty()) + if (!srcString.IsEmpty()) { int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1); if (numChars < 0) throw "Your environment does not support UNICODE"; @@ -87,7 +87,7 @@ AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) for (int i = 0; i < srcString.Length(); i++) resultString += char(srcString[i]); /* - if(!srcString.IsEmpty()) + if (!srcString.IsEmpty()) { int numRequiredBytes = srcString.Length() * 6 + 1; int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes); diff --git a/CPP/Common/Wildcard.cpp b/CPP/Common/Wildcard.cpp index 05a3f5a3..141c5dd6 100755 --- a/CPP/Common/Wildcard.cpp +++ b/CPP/Common/Wildcard.cpp @@ -106,8 +106,8 @@ void SplitPathToParts(const UString &path, UStringVector &pathParts) void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name) { int i; - for(i = path.Length() - 1; i >= 0; i--) - if(IsCharDirLimiter(path[i])) + for (i = path.Length() - 1; i >= 0; i--) + if (IsCharDirLimiter(path[i])) break; dirPrefix = path.Left(i + 1); name = path.Mid(i + 1); @@ -116,8 +116,8 @@ void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name) UString ExtractDirPrefixFromPath(const UString &path) { int i; - for(i = path.Length() - 1; i >= 0; i--) - if(IsCharDirLimiter(path[i])) + for (i = path.Length() - 1; i >= 0; i--) + if (IsCharDirLimiter(path[i])) break; return path.Left(i + 1); } @@ -125,8 +125,8 @@ UString ExtractDirPrefixFromPath(const UString &path) UString ExtractFileNameFromPath(const UString &path) { int i; - for(i = path.Length() - 1; i >= 0; i--) - if(IsCharDirLimiter(path[i])) + for (i = path.Length() - 1; i >= 0; i--) + if (IsCharDirLimiter(path[i])) break; return path.Mid(i + 1); } @@ -309,7 +309,7 @@ bool CCensorNode::CheckPath(const UString &path, bool isFile, bool &include) con bool CCensorNode::CheckPath(const UString &path, bool isFile) const { bool include; - if(CheckPath(path, isFile, include)) + if (CheckPath(path, isFile, include)) return include; return false; } |