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,19 +681,17 @@ 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);
if (start != std::wstring::npos)
{ {
size_t si = start + 1; size_t si = start + 1;
end = result.find(L']', si); size_t end = result.find(L']', si);
if (end != std::wstring::npos) if (end == std::wstring::npos)
{ {
next = result.find(L'[', si); break;
}
size_t next = result.find(L'[', si);
if (next == std::wstring::npos || end < next) if (next == std::wstring::npos || end < next)
{ {
size_t ei = end - 1; size_t ei = end - 1;
@ -710,11 +708,12 @@ bool CConfigParser::ReplaceMeasures(std::wstring& result)
CMeasure* measure = GetMeasure(var); CMeasure* measure = GetMeasure(var);
if (measure) if (measure)
{ {
const std::wstring& value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false); const WCHAR* value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
size_t valueLen = wcslen(value);
// Measure found, replace it with the value // Measure found, replace it with the value
result.replace(start, end - start + 1, value); result.replace(start, end - start + 1, value, valueLen);
start += value.length(); start += valueLen;
replaced = true; replaced = true;
} }
else else
@ -739,17 +738,6 @@ bool CConfigParser::ReplaceMeasures(std::wstring& result)
start = next; start = next;
} }
} }
else
{
loop = false;
}
}
else
{
loop = false;
}
}
while (loop);
return replaced; return replaced;
} }

View File

@ -627,23 +627,16 @@ 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)
{
_itow_s((int)val, buffer, 10);
}
else
{
_snwprintf_s(format, _TRUNCATE, L"%%.%if", decimals); _snwprintf_s(format, _TRUNCATE, L"%%.%if", decimals);
_snwprintf_s(buffer, _TRUNCATE, format, val); _snwprintf_s(buffer, _TRUNCATE, format, val);
} }
}
else if (autoScale != AUTOSCALE_OFF) else if (autoScale != AUTOSCALE_OFF)
{ {
GetScaledValue(autoScale, decimals, GetValue(), buffer, _countof(buffer)); GetScaledValue(autoScale, decimals, GetValue(), buffer, _countof(buffer));
@ -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);