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; bool replaced = false;
size_t start = 0, end, next; size_t start = 0;
bool loop = true; while ((start = result.find(L'[', start)) != std::wstring::npos)
do
{ {
start = result.find(L'[', start); size_t si = start + 1;
if (start != std::wstring::npos) size_t end = result.find(L']', si);
if (end == std::wstring::npos)
{ {
size_t si = start + 1; break;
end = result.find(L']', si); }
if (end != std::wstring::npos)
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); result.erase(ei, 1);
if (next == std::wstring::npos || end < next) result.erase(si, 1);
{ start = ei;
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;
}
} }
else 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 else
{ {
loop = false; start = next;
} }
} }
while (loop);
return replaced; return replaced;
} }

View File

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