From 3d33a16f9f600357343aa624e9011d78f10558c7 Mon Sep 17 00:00:00 2001 From: spx Date: Tue, 10 Aug 2010 18:23:10 +0000 Subject: [PATCH] - Additional fix for r502. Functions/Measures/Counter in Formula are now case-insensitive in MeasureCalc. - "[Measure]" is now case-insensitive in DynamicVariables. --- Library/ConfigParser.cpp | 24 +++++++++++++++++++----- Library/ConfigParser.h | 1 + Library/MeasureCalc.cpp | 8 +------- Library/ccalc-0.5.1/strmap.c | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 83408a34..a57225a1 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -504,12 +504,12 @@ bool CConfigParser::ReplaceMeasures(std::wstring& result) if (pos2 == std::wstring::npos || end < pos2) { std::wstring var(result.begin() + pos + 1, result.begin() + end); - - std::map::const_iterator iter = m_Measures.find(var); - if (iter != m_Measures.end()) + + CMeasure* measure = GetMeasure(var); + if (measure) { - std::wstring value = (*iter).second->GetStringValue(false, 1, 5, false); - + std::wstring value = measure->GetStringValue(false, 1, 5, false); + // Measure found, replace it with the value result.replace(result.begin() + pos, result.begin() + end + 1, value); start = pos + value.length(); @@ -612,6 +612,20 @@ void CConfigParser::AddMeasure(CMeasure* pMeasure) } } +CMeasure* CConfigParser::GetMeasure(const std::wstring& name) +{ + std::map::const_iterator iter = m_Measures.begin(); + for ( ; iter != m_Measures.end(); ++iter) + { + if (wcsicmp((*iter).first.c_str(), name.c_str()) == 0) + { + return (*iter).second; + } + } + + return NULL; +} + double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue) { TCHAR buffer[256]; diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index be059a72..bb86d77f 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -70,6 +70,7 @@ private: void ReadVariables(); bool ReplaceVariables(std::wstring& result); bool ReplaceMeasures(std::wstring& result); + CMeasure* GetMeasure(const std::wstring& name); void ReadIniFile(const std::vector& iniFileMappings, const std::wstring& strFileName, int depth = 0); void SetValue(const std::wstring& strSection, const std::wstring& strKey, const std::wstring& strValue); diff --git a/Library/MeasureCalc.cpp b/Library/MeasureCalc.cpp index a5ad5c38..149453d4 100644 --- a/Library/MeasureCalc.cpp +++ b/Library/MeasureCalc.cpp @@ -141,7 +141,6 @@ void CMeasureCalc::ReadConfig(CConfigParser& parser, const WCHAR* section) ** FormulaReplace ** ** This replaces the word Random in m_Formula with a random number -** and all cases of counter with Counter ** */ void CMeasureCalc::FormulaReplace() @@ -151,7 +150,7 @@ void CMeasureCalc::FormulaReplace() m_Formula = m_FormulaHolder; std::wstring::size_type loc = 0; - while ((loc = m_Formula.find_first_of(L"RrCc", loc)) != std::wstring::npos) + while ((loc = m_Formula.find_first_of(L"Rr", loc)) != std::wstring::npos) { if (wcsnicmp(L"Random", m_Formula.c_str() + loc, 6) == 0) { @@ -165,11 +164,6 @@ void CMeasureCalc::FormulaReplace() m_Formula.replace(loc, 6, buffer); loc += wcslen(buffer); } - else if (wcsnicmp(L"Counter", m_Formula.c_str() + loc, 7) == 0) - { - m_Formula.replace(loc, 7, L"Counter"); - loc += 7; - } else { ++loc; diff --git a/Library/ccalc-0.5.1/strmap.c b/Library/ccalc-0.5.1/strmap.c index f3eef522..018231f5 100644 --- a/Library/ccalc-0.5.1/strmap.c +++ b/Library/ccalc-0.5.1/strmap.c @@ -108,7 +108,7 @@ int StrMap_LenIndexOf( hqStrMap* strmap, const char *str, size_t len, void **dat char *Rec = strmap->FList; for (i=0; iFCount; i++) { int recLen = *(int*)(Rec + sizeof(char*)); - if (recLen==len && strncmp( str, *(char**)Rec, recLen )==0 ) { + if (recLen==len && strnicmp( str, *(char**)Rec, recLen )==0 ) { *data = (Rec + sizeof(char*) + sizeof(int)); return i; }