From deef3b0ab49d055b06ab66e6ad84a66213b0cfa4 Mon Sep 17 00:00:00 2001 From: spx Date: Sat, 12 Nov 2011 15:36:05 +0000 Subject: [PATCH] Minor tweaks. --- Library/ConfigParser.cpp | 53 ++++++++++++++++++++++------------------ Library/ConfigParser.h | 7 +++--- Library/DialogManage.cpp | 6 ++--- Library/Meter.h | 2 +- Library/MeterWindow.cpp | 2 +- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 104818d8..3d2de5dc 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -87,7 +87,7 @@ void CConfigParser::Initialize(LPCTSTR filename, CRainmeter* pRainmeter, CMeterW // Clear and minimize std::unordered_set().swap(m_FoundSections); - std::vector().swap(m_ListVariables); + std::list().swap(m_ListVariables); } /* @@ -124,7 +124,7 @@ void CConfigParser::SetBuiltInVariables(CRainmeter* pRainmeter, CMeterWindow* me */ void CConfigParser::ReadVariables() { - std::vector::const_iterator iter = m_ListVariables.begin(); + std::list::const_iterator iter = m_ListVariables.begin(); for ( ; iter != m_ListVariables.end(); ++iter) { SetVariable((*iter), ReadString(L"Variables", (*iter).c_str(), L"", false)); @@ -1108,13 +1108,13 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int { if (*pos) { - std::wstring strTmp = StrToLower(pos); - if (m_FoundSections.insert(strTmp).second) + std::wstring section = pos; + if (m_FoundSections.insert(StrToLower(section)).second) { - m_Sections.push_back(pos); + m_Sections.push_back(section); } - sections.push_back(pos); - pos += strTmp.size() + 1; + sections.push_back(section); + pos += section.size() + 1; } else // Empty string { @@ -1125,15 +1125,16 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int else { // Special case: Read only "Rainmeter" and specified section from "Rainmeter.ini" - sections.push_back(L"Rainmeter"); - sections.push_back(config); + const std::wstring strRainmeter = L"Rainmeter"; + const std::wstring strConfig = config; + + sections.push_back(strRainmeter); + sections.push_back(strConfig); if (depth == 0) // Add once { - m_Sections.push_back(L"Rainmeter"); - m_Sections.push_back(config); - m_FoundSections.insert(L"rainmeter"); - m_FoundSections.insert(StrToLower(config)); + m_Sections.push_back(strRainmeter); + m_Sections.push_back(strConfig); } } @@ -1167,25 +1168,29 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int { if (*pos) { - std::wstring key = pos; - std::wstring::size_type len = key.length(), sep = key.find_first_of(L'='); - if (sep != std::wstring::npos && sep != 0) + size_t len = wcslen(pos); + WCHAR* sep = wmemchr(pos, L'=', len); + if (sep != NULL && sep != pos) { - std::wstring value = key.substr(sep + 1, len - sep); - key.erase(sep); + size_t clen = sep - pos; // key's length + std::wstring key(pos, clen); if (foundKeys.insert(StrToLowerC(key)).second) { + ++sep; + clen = len - (clen + 1); // value's length + // Trim surrounded quotes from value - std::wstring::size_type valueLen = value.length(); - if (valueLen >= 2 && ( - (value[0] == L'\"' && value[valueLen - 1] == L'\"') || - (value[0] == L'\'' && value[valueLen - 1] == L'\''))) + if (clen >= 2 && ( + (sep[0] == L'\"' && sep[clen - 1] == L'\"') || + (sep[0] == L'\'' && sep[clen - 1] == L'\''))) { - valueLen -= 2; - value.assign(value, 1, valueLen); + clen -= 2; + ++sep; } + std::wstring value(sep, clen); + if (wcsncmp(key.c_str(), L"@include", 8) == 0) { ReadVariables(); diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index 117ac34f..a36db4d1 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -77,8 +77,7 @@ public: bool ReadFormula(const std::wstring& result, double* resultValue); const std::wstring& GetFilename() { return m_Filename; } - const std::vector& GetSections() { return m_Sections; } - bool IsSectionDefined(LPCTSTR section) { return m_FoundSections.find(StrToLower(section)) != m_FoundSections.end(); } + const std::list& GetSections() { return m_Sections; } bool ReplaceVariables(std::wstring& result); bool ReplaceMeasures(std::wstring& result); @@ -125,11 +124,11 @@ private: bool m_LastDefaultUsed; bool m_LastValueDefined; - std::vector m_Sections; // The sections must be an ordered array + std::list m_Sections; // The sections must be an ordered array std::unordered_map m_Values; std::unordered_set m_FoundSections; - std::vector m_ListVariables; + std::list m_ListVariables; std::unordered_map m_BuiltInVariables; // Built-in variables std::unordered_map m_Variables; // User-defined variables diff --git a/Library/DialogManage.cpp b/Library/DialogManage.cpp index 77913c81..f02730e7 100644 --- a/Library/DialogManage.cpp +++ b/Library/DialogManage.cpp @@ -1490,11 +1490,9 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam) CConfigParser parser; parser.Initialize(path.c_str(), Rainmeter); - const std::vector& sections = parser.GetSections(); - std::vector::const_iterator iter = sections.begin(); - // Remove sections with Active=0 - for ( ; iter != sections.end(); ++iter) + std::list::const_iterator iter = parser.GetSections().begin(); + for ( ; iter != parser.GetSections().end(); ++iter) { if (parser.GetValue(*iter, L"Active", L"") == L"0") { diff --git a/Library/Meter.h b/Library/Meter.h index 19a7bea2..708a5595 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -24,11 +24,11 @@ #include #include #include "Litestep.h" +#include "ConfigParser.h" #include "MeterWindow.h" #include "Group.h" class CMeasure; -class CConfigParser; class CMeter : public CGroup { diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 8c29d2ec..7662be23 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -2246,7 +2246,7 @@ bool CMeterWindow::ReadSkin() m_HasButtons = false; // Get all the sections (i.e. different meters, measures and the other stuff) - std::vector::const_iterator iter = m_Parser.GetSections().begin(); + std::list::const_iterator iter = m_Parser.GetSections().begin(); for ( ; iter != m_Parser.GetSections().end(); ++iter) { const WCHAR* section = (*iter).c_str();