diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 8068cd1f..afea0fde 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -153,10 +153,10 @@ void CConfigParser::SetVariable(std::unordered_map& } /* -** Gets a value for the variable. Returns true if variable found. +** Gets a value for the variable. Returns NULL if not found. ** */ -bool CConfigParser::GetVariable(const std::wstring& strVariable, std::wstring& strValue) +const std::wstring* CConfigParser::GetVariable(const std::wstring& strVariable) { const std::wstring strTmp = StrToUpper(strVariable); @@ -164,31 +164,24 @@ bool CConfigParser::GetVariable(const std::wstring& strVariable, std::wstring& s std::unordered_map::const_iterator iter = m_BuiltInVariables.find(strTmp); if (iter != m_BuiltInVariables.end()) { - // Built-in variable found - strValue = (*iter).second; - return true; + return &(*iter).second; } // #2: Monitor variables iter = c_MonitorVariables.find(strTmp); if (iter != c_MonitorVariables.end()) { - // SCREENAREA/WORKAREA variable found - strValue = (*iter).second; - return true; + return &(*iter).second; } // #3: User-defined variables iter = m_Variables.find(strTmp); if (iter != m_Variables.end()) { - // Variable found - strValue = (*iter).second; - return true; + return &(*iter).second; } - // Not found - return false; + return NULL; } /* @@ -577,13 +570,12 @@ bool CConfigParser::ReplaceVariables(std::wstring& result) else { std::wstring strVariable = result.substr(si, end - si); - std::wstring strValue; - - if (GetVariable(strVariable, strValue)) + const std::wstring* value = GetVariable(strVariable); + if (value) { // Variable found, replace it with the value - result.replace(start, end - start + 1, strValue); - start += strValue.length(); + result.replace(start, end - start + 1, *value); + start += (*value).length(); replaced = true; } else diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index 068e5124..ad4246c8 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -46,7 +46,7 @@ public: void AddMeasure(CMeasure* pMeasure); CMeasure* GetMeasure(const std::wstring& name); - bool GetVariable(const std::wstring& strVariable, std::wstring& strValue); + const std::wstring* GetVariable(const std::wstring& strVariable); void SetVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_Variables, strVariable, strValue); } void SetBuiltInVariable(const std::wstring& strVariable, const std::wstring& strValue) { SetVariable(m_BuiltInVariables, strVariable, strValue); } diff --git a/Library/Export.cpp b/Library/Export.cpp index 3f7ca779..0ae0d5cf 100644 --- a/Library/Export.cpp +++ b/Library/Export.cpp @@ -178,9 +178,10 @@ LPCWSTR PluginBridge(LPCWSTR command, LPCWSTR data) { const std::wstring& variable = subStrings[1]; - if (meterWindow->GetParser().GetVariable(variable, g_Buffer)) + const std::wstring* value = meterWindow->GetParser().GetVariable(variable); + if (value) { - return g_Buffer.c_str(); + return (*value).c_str(); } } } diff --git a/Library/lua/glue/LuaMeterWindow.cpp b/Library/lua/glue/LuaMeterWindow.cpp index bf672eb7..c892a31e 100644 --- a/Library/lua/glue/LuaMeterWindow.cpp +++ b/Library/lua/glue/LuaMeterWindow.cpp @@ -108,9 +108,10 @@ static int GetVariable(lua_State* L) CMeterWindow* self = GetSelf(L); std::wstring strTmp = LuaManager::ToWide(L, 2); - if (self->GetParser().GetVariable(strTmp, strTmp)) + const std::wstring* value = self->GetParser().GetVariable(strTmp); + if (value) { - LuaManager::PushWide(L, strTmp.c_str()); + LuaManager::PushWide(L, (*value).c_str()); } else {