This commit is contained in:
Birunthan Mohanathas 2012-08-04 21:27:21 +03:00
parent 78542ec2be
commit e2ce7d59a7
2 changed files with 49 additions and 73 deletions

View File

@ -681,75 +681,63 @@ bool CConfigParser::ReplaceMeasures(std::wstring& result)
{
bool replaced = false;
size_t start = 0, end, next;
bool loop = true;
do
size_t start = 0;
while ((start = result.find(L'[', start)) != std::wstring::npos)
{
start = result.find(L'[', start);
if (start != std::wstring::npos)
size_t si = start + 1;
size_t end = result.find(L']', si);
if (end == std::wstring::npos)
{
size_t si = start + 1;
end = result.find(L']', si);
if (end != std::wstring::npos)
break;
}
size_t next = result.find(L'[', si);
if (next == std::wstring::npos || end < next)
{
size_t ei = end - 1;
if (si != ei && result[si] == L'*' && result[ei] == L'*')
{
next = result.find(L'[', si);
if (next == std::wstring::npos || end < next)
{
size_t ei = end - 1;
if (si != ei && result[si] == L'*' && result[ei] == L'*')
{
result.erase(ei, 1);
result.erase(si, 1);
start = ei;
}
else
{
std::wstring var = result.substr(si, end - si);
CMeasure* measure = GetMeasure(var);
if (measure)
{
const std::wstring& value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
// Measure found, replace it with the value
result.replace(start, end - start + 1, value);
start += value.length();
replaced = true;
}
else
{
std::wstring value;
if (GetSectionVariables(var, value))
{
// Measure found, replace it with the value
result.replace(start, end - start + 1, value);
start += value.length();
replaced = true;
}
else
{
start = end;
}
}
}
}
else
{
start = next;
}
result.erase(ei, 1);
result.erase(si, 1);
start = ei;
}
else
{
loop = false;
std::wstring var = result.substr(si, end - si);
CMeasure* measure = GetMeasure(var);
if (measure)
{
const WCHAR* value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
size_t valueLen = wcslen(value);
// Measure found, replace it with the value
result.replace(start, end - start + 1, value, valueLen);
start += valueLen;
replaced = true;
}
else
{
std::wstring value;
if (GetSectionVariables(var, value))
{
// Measure found, replace it with the value
result.replace(start, end - start + 1, value);
start += value.length();
replaced = true;
}
else
{
start = end;
}
}
}
}
else
{
loop = false;
start = next;
}
}
while (loop);
return replaced;
}

View File

@ -627,22 +627,15 @@ double CMeasure::GetValueRange()
*/
const WCHAR* CMeasure::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
static WCHAR buffer[MAX_LINE_LENGTH];
static WCHAR buffer[128];
WCHAR format[32];
if (percentual)
{
double val = 100.0 * GetRelativeValue();
if (decimals == 0)
{
_itow_s((int)val, buffer, 10);
}
else
{
_snwprintf_s(format, _TRUNCATE, L"%%.%if", decimals);
_snwprintf_s(buffer, _TRUNCATE, format, val);
}
_snwprintf_s(format, _TRUNCATE, L"%%.%if", decimals);
_snwprintf_s(buffer, _TRUNCATE, format, val);
}
else if (autoScale != AUTOSCALE_OFF)
{
@ -652,12 +645,7 @@ const WCHAR* CMeasure::GetStringValue(AUTOSCALE autoScale, double scale, int dec
{
double val = GetValue() / scale;
if (decimals == 0)
{
val += (val >= 0) ? 0.5 : -0.5;
_snwprintf_s(buffer, _TRUNCATE, L"%lli", (LONGLONG)val);
}
else if (decimals == -1)
if (decimals == -1)
{
int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", val);
RemoveTrailingZero(buffer, len);