Minor tweaks.

This commit is contained in:
spx 2011-11-12 15:36:05 +00:00
parent 9f629fac62
commit deef3b0ab4
5 changed files with 36 additions and 34 deletions

View File

@ -87,7 +87,7 @@ void CConfigParser::Initialize(LPCTSTR filename, CRainmeter* pRainmeter, CMeterW
// Clear and minimize // Clear and minimize
std::unordered_set<std::wstring>().swap(m_FoundSections); std::unordered_set<std::wstring>().swap(m_FoundSections);
std::vector<std::wstring>().swap(m_ListVariables); std::list<std::wstring>().swap(m_ListVariables);
} }
/* /*
@ -124,7 +124,7 @@ void CConfigParser::SetBuiltInVariables(CRainmeter* pRainmeter, CMeterWindow* me
*/ */
void CConfigParser::ReadVariables() void CConfigParser::ReadVariables()
{ {
std::vector<std::wstring>::const_iterator iter = m_ListVariables.begin(); std::list<std::wstring>::const_iterator iter = m_ListVariables.begin();
for ( ; iter != m_ListVariables.end(); ++iter) for ( ; iter != m_ListVariables.end(); ++iter)
{ {
SetVariable((*iter), ReadString(L"Variables", (*iter).c_str(), L"", false)); 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) if (*pos)
{ {
std::wstring strTmp = StrToLower(pos); std::wstring section = pos;
if (m_FoundSections.insert(strTmp).second) if (m_FoundSections.insert(StrToLower(section)).second)
{ {
m_Sections.push_back(pos); m_Sections.push_back(section);
} }
sections.push_back(pos); sections.push_back(section);
pos += strTmp.size() + 1; pos += section.size() + 1;
} }
else // Empty string else // Empty string
{ {
@ -1125,15 +1125,16 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
else else
{ {
// Special case: Read only "Rainmeter" and specified section from "Rainmeter.ini" // Special case: Read only "Rainmeter" and specified section from "Rainmeter.ini"
sections.push_back(L"Rainmeter"); const std::wstring strRainmeter = L"Rainmeter";
sections.push_back(config); const std::wstring strConfig = config;
sections.push_back(strRainmeter);
sections.push_back(strConfig);
if (depth == 0) // Add once if (depth == 0) // Add once
{ {
m_Sections.push_back(L"Rainmeter"); m_Sections.push_back(strRainmeter);
m_Sections.push_back(config); m_Sections.push_back(strConfig);
m_FoundSections.insert(L"rainmeter");
m_FoundSections.insert(StrToLower(config));
} }
} }
@ -1167,25 +1168,29 @@ void CConfigParser::ReadIniFile(const std::wstring& iniFile, LPCTSTR config, int
{ {
if (*pos) if (*pos)
{ {
std::wstring key = pos; size_t len = wcslen(pos);
std::wstring::size_type len = key.length(), sep = key.find_first_of(L'='); WCHAR* sep = wmemchr(pos, L'=', len);
if (sep != std::wstring::npos && sep != 0) if (sep != NULL && sep != pos)
{ {
std::wstring value = key.substr(sep + 1, len - sep); size_t clen = sep - pos; // key's length
key.erase(sep);
std::wstring key(pos, clen);
if (foundKeys.insert(StrToLowerC(key)).second) if (foundKeys.insert(StrToLowerC(key)).second)
{ {
++sep;
clen = len - (clen + 1); // value's length
// Trim surrounded quotes from value // Trim surrounded quotes from value
std::wstring::size_type valueLen = value.length(); if (clen >= 2 && (
if (valueLen >= 2 && ( (sep[0] == L'\"' && sep[clen - 1] == L'\"') ||
(value[0] == L'\"' && value[valueLen - 1] == L'\"') || (sep[0] == L'\'' && sep[clen - 1] == L'\'')))
(value[0] == L'\'' && value[valueLen - 1] == L'\'')))
{ {
valueLen -= 2; clen -= 2;
value.assign(value, 1, valueLen); ++sep;
} }
std::wstring value(sep, clen);
if (wcsncmp(key.c_str(), L"@include", 8) == 0) if (wcsncmp(key.c_str(), L"@include", 8) == 0)
{ {
ReadVariables(); ReadVariables();

View File

@ -77,8 +77,7 @@ public:
bool ReadFormula(const std::wstring& result, double* resultValue); bool ReadFormula(const std::wstring& result, double* resultValue);
const std::wstring& GetFilename() { return m_Filename; } const std::wstring& GetFilename() { return m_Filename; }
const std::vector<std::wstring>& GetSections() { return m_Sections; } const std::list<std::wstring>& GetSections() { return m_Sections; }
bool IsSectionDefined(LPCTSTR section) { return m_FoundSections.find(StrToLower(section)) != m_FoundSections.end(); }
bool ReplaceVariables(std::wstring& result); bool ReplaceVariables(std::wstring& result);
bool ReplaceMeasures(std::wstring& result); bool ReplaceMeasures(std::wstring& result);
@ -125,11 +124,11 @@ private:
bool m_LastDefaultUsed; bool m_LastDefaultUsed;
bool m_LastValueDefined; bool m_LastValueDefined;
std::vector<std::wstring> m_Sections; // The sections must be an ordered array std::list<std::wstring> m_Sections; // The sections must be an ordered array
std::unordered_map<std::wstring, std::wstring> m_Values; std::unordered_map<std::wstring, std::wstring> m_Values;
std::unordered_set<std::wstring> m_FoundSections; std::unordered_set<std::wstring> m_FoundSections;
std::vector<std::wstring> m_ListVariables; std::list<std::wstring> m_ListVariables;
std::unordered_map<std::wstring, std::wstring> m_BuiltInVariables; // Built-in variables std::unordered_map<std::wstring, std::wstring> m_BuiltInVariables; // Built-in variables
std::unordered_map<std::wstring, std::wstring> m_Variables; // User-defined variables std::unordered_map<std::wstring, std::wstring> m_Variables; // User-defined variables

View File

@ -1490,11 +1490,9 @@ INT_PTR CDialogManage::CTabThemes::OnCommand(WPARAM wParam, LPARAM lParam)
CConfigParser parser; CConfigParser parser;
parser.Initialize(path.c_str(), Rainmeter); parser.Initialize(path.c_str(), Rainmeter);
const std::vector<std::wstring>& sections = parser.GetSections();
std::vector<std::wstring>::const_iterator iter = sections.begin();
// Remove sections with Active=0 // Remove sections with Active=0
for ( ; iter != sections.end(); ++iter) std::list<std::wstring>::const_iterator iter = parser.GetSections().begin();
for ( ; iter != parser.GetSections().end(); ++iter)
{ {
if (parser.GetValue(*iter, L"Active", L"") == L"0") if (parser.GetValue(*iter, L"Active", L"") == L"0")
{ {

View File

@ -24,11 +24,11 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "Litestep.h" #include "Litestep.h"
#include "ConfigParser.h"
#include "MeterWindow.h" #include "MeterWindow.h"
#include "Group.h" #include "Group.h"
class CMeasure; class CMeasure;
class CConfigParser;
class CMeter : public CGroup class CMeter : public CGroup
{ {

View File

@ -2246,7 +2246,7 @@ bool CMeterWindow::ReadSkin()
m_HasButtons = false; m_HasButtons = false;
// Get all the sections (i.e. different meters, measures and the other stuff) // Get all the sections (i.e. different meters, measures and the other stuff)
std::vector<std::wstring>::const_iterator iter = m_Parser.GetSections().begin(); std::list<std::wstring>::const_iterator iter = m_Parser.GetSections().begin();
for ( ; iter != m_Parser.GetSections().end(); ++iter) for ( ; iter != m_Parser.GetSections().end(); ++iter)
{ {
const WCHAR* section = (*iter).c_str(); const WCHAR* section = (*iter).c_str();