From 569a151c6ca5f8beff8bb91d3d24d8fb5500b01c Mon Sep 17 00:00:00 2001 From: spx Date: Tue, 8 Nov 2011 17:21:29 +0000 Subject: [PATCH] - Switched from size()>0 to empty(). - Code cleanup. --- Library/ConfigParser.cpp | 18 +++++++++--------- Library/Group.cpp | 6 +++--- Library/Measure.cpp | 14 ++++++-------- Library/MeasureTime.cpp | 4 ++-- Library/MeterWindow.cpp | 11 ++++------- Library/Rainmeter.cpp | 4 ++-- Library/System.cpp | 6 +++--- Library/TrayWindow.cpp | 4 ++-- 8 files changed, 31 insertions(+), 36 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index bdd73d84..b62674bd 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -599,7 +599,7 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT if (&strValue == &strDefault) { // If the template is defined read the value from there. - if (m_StyleTemplate.size() > 0) + if (!m_StyleTemplate.empty()) { std::vector::const_reverse_iterator iter = m_StyleTemplate.rbegin(); for ( ; iter != m_StyleTemplate.rend(); ++iter) @@ -618,7 +618,7 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT } } - if (m_LastUsedStyle.size() == 0) // No template found + if (m_LastUsedStyle.empty()) // No template found { result = strDefault; m_LastDefaultUsed = true; @@ -630,7 +630,7 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT result = strValue; } - if (result.size() > 0) + if (!result.empty()) { m_LastValueDefined = true; @@ -662,7 +662,7 @@ bool CConfigParser::IsKeyDefined(LPCTSTR section, LPCTSTR key) bool CConfigParser::IsValueDefined(LPCTSTR section, LPCTSTR key) { const std::wstring& result = ReadString(section, key, L"", false); - return (!m_LastDefaultUsed && result.size() > 0); + return (!m_LastDefaultUsed && !result.empty()); } void CConfigParser::AddMeasure(CMeasure* pMeasure) @@ -695,7 +695,7 @@ std::vector CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR ke { std::vector result; const std::wstring& string = ReadString(section, key, L""); - if (string.size() > 0) + if (!string.empty()) { std::wstring tmp = string; if (tmp[tmp.length() - 1] != L';') @@ -734,7 +734,7 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue) const std::wstring& result = ReadString(section, key, L""); // Formulas must be surrounded by parenthesis - if (result.size() > 0 && result[0] == L'(' && result[result.size() - 1] == L')') + if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')') { double resultValue = defValue; char* errMsg = MathParser_Parse(m_Parser, ConvertToAscii(result.c_str()).c_str(), &resultValue); @@ -761,7 +761,7 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue) bool CConfigParser::ReadFormula(const std::wstring& result, double* resultValue) { // Formulas must be surrounded by parenthesis - if (result.size() > 0 && result[0] == L'(' && result[result.size() - 1] == L')') + if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')') { char* errMsg = MathParser_Parse(m_Parser, ConvertToAscii(result.c_str()).c_str(), resultValue); if (errMsg != NULL) @@ -833,7 +833,7 @@ std::vector CConfigParser::Tokenize(const std::wstring& str, const */ void CConfigParser::Shrink(std::vector& vec) { - if (vec.size() > 0) + if (!vec.empty()) { std::vector::iterator iter = vec.begin(); while (iter != vec.end()) @@ -1059,7 +1059,7 @@ void CConfigParser::ReadIniFile(const std::vector& iniFileMappings // Avoid "IniFileMapping" std::wstring iniRead = CSystem::GetTemporaryFile(iniFileMappings, iniFile); - bool temporary = (iniRead.size() > 0 && iniRead != L"<>"); + bool temporary = (!iniRead.empty() && (iniRead.size() != 1 || iniRead[0] != L'?')); if (temporary) { diff --git a/Library/Group.cpp b/Library/Group.cpp index 3bfade87..a6312972 100644 --- a/Library/Group.cpp +++ b/Library/Group.cpp @@ -27,12 +27,12 @@ */ void CGroup::InitializeGroup(const std::wstring& groups) { - if (groups != m_OldGroups) + if (wcscmp(groups.c_str(), m_OldGroups.c_str()) != 0) { m_OldGroups = groups; m_Groups.clear(); - if (groups.size() > 0) + if (!groups.empty()) { std::vector vGroups = CConfigParser::Tokenize(groups, L"|"); @@ -40,7 +40,7 @@ void CGroup::InitializeGroup(const std::wstring& groups) for ( ; iter != vGroups.end(); ++iter) { std::wstring group = CreateGroup(*iter); - if (group.size() > 0) + if (!group.empty()) { m_Groups.insert(group); } diff --git a/Library/Measure.cpp b/Library/Measure.cpp index 6a4d5e81..7b7325a2 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -349,16 +349,16 @@ bool CMeasure::ParseSubstitute(std::wstring buffer) { std::wstring word1 = ExtractWord(buffer); std::wstring sep = ExtractWord(buffer); - if (sep != L":") return false; + if (sep.size() != 1 || sep[0] != L':') return false; std::wstring word2 = ExtractWord(buffer); - if (word1 != word2) + if (wcscmp(word1.c_str(), word2.c_str()) != 0) { m_Substitute.push_back(std::pair(word1, word2)); } - sep = ExtractWord(buffer); - if (!sep.empty() && sep != L",") return false; + std::wstring sep2 = ExtractWord(buffer); + if (!sep2.empty() && (sep2.size() != 1 || sep2[0] != L',')) return false; } while (!buffer.empty()); @@ -374,12 +374,10 @@ bool CMeasure::ParseSubstitute(std::wstring buffer) */ std::wstring CMeasure::ExtractWord(std::wstring& buffer) { - std::wstring::size_type end, len; + std::wstring::size_type end, len = buffer.size(); std::wstring ret; - if (buffer.empty()) return ret; - - len = buffer.size(); + if (len == 0) return ret; // Remove whitespaces end = 0; diff --git a/Library/MeasureTime.cpp b/Library/MeasureTime.cpp index 431a0aba..93ac4e41 100644 --- a/Library/MeasureTime.cpp +++ b/Library/MeasureTime.cpp @@ -113,7 +113,7 @@ bool CMeasureTime::Update() m_Time.QuadPart += m_DeltaTime.QuadPart; - if (m_Format.size() > 0) + if (!m_Format.empty()) { // If there is some date format, parse the value from it instead WCHAR* tmpSz = new WCHAR[MAX_LINE_LENGTH]; @@ -195,7 +195,7 @@ const WCHAR* CMeasureTime::GetStringValue(AUTOSCALE autoScale, double scale, int today.tm_year = sysToday.wYear - 1900; // Create the string - if (m_Format.size() > 0) + if (!m_Format.empty()) { if (_wcsicmp(L"locale-time", m_Format.c_str()) == 0) { diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index ba43b9cc..d1e5921c 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -2563,15 +2563,12 @@ bool CMeterWindow::ResizeWindow(bool reset) SetWindowSizeVariables(m_WindowW, m_WindowH); - // If Background is not set, take a copy from the desktop - if (m_Background == NULL) + if (!m_NativeTransparency) { - if (m_BackgroundMode == BGMODE_COPY) + // If Background is not set, take a copy from the desktop + if (m_Background == NULL && m_BackgroundMode == BGMODE_COPY) { - if (!m_NativeTransparency) - { - m_Background = GrabDesktop(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH); - } + m_Background = GrabDesktop(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH); } } diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 47c6f07f..3db77f51 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -344,7 +344,7 @@ std::vector CRainmeter::ParseString(LPCTSTR str) } } - if (arg.size() > 0) + if (!arg.empty()) { // Strip quotes while ((pos = arg.find(L'"')) != std::wstring::npos) @@ -652,7 +652,7 @@ void CRainmeter::RainmeterWriteKeyValue(const WCHAR* arg) std::vector iniFileMappings; CSystem::GetIniFileMappingList(iniFileMappings); std::wstring iniWrite = CSystem::GetTemporaryFile(iniFileMappings, iniFile); - if (iniWrite == L"<>") // error occurred + if (iniWrite.size() == 1 && iniWrite[0] == L'?') // error occurred { return; } diff --git a/Library/System.cpp b/Library/System.cpp index 04497d11..f16a605e 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -1229,7 +1229,7 @@ void CSystem::GetIniFileMappingList(std::vector& iniFileMappings) ** GetTemporaryFile ** ** Prepares a temporary file if iniFile is included in the "IniFileMapping" entries. -** If iniFile is not included, returns a empty string. If error occurred, returns "<>". +** If iniFile is not included, returns a empty string. If error occurred, returns "?". ** Note that a temporary file must be deleted by caller. ** */ @@ -1272,14 +1272,14 @@ std::wstring CSystem::GetTemporaryFile(const std::vector& iniFileM else // temporary is reserved or failed { RemoveFile(temporary); - if (tmp.empty()) tmp = L"<>"; + if (tmp.empty()) tmp = L"?"; return tmp; } } else // failed { LogWithArgs(LOG_ERROR, L"Unable to create temporary file to: %s", temporary.c_str()); - return L"<>"; + return L"?"; } } } diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index 45b037df..d1d8fd7b 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -205,9 +205,9 @@ HICON CTrayWindow::CreateTrayIcon(double value) trayBitmap.GetHICON(&icon); return icon; } - else if (m_MeterType == TRAY_METER_TYPE_BITMAP && (m_Bitmap || m_TrayIcons.size() > 0)) + else if (m_MeterType == TRAY_METER_TYPE_BITMAP && (m_Bitmap || !m_TrayIcons.empty())) { - if (m_TrayIcons.size() > 0) + if (!m_TrayIcons.empty()) { size_t frame = 0; size_t frameCount = m_TrayIcons.size();