Using wstring instead of wstringstream where appropriate (#881)

This commit is contained in:
Scott Freeman
2019-12-19 04:50:31 -05:00
committed by Rudy Huyn
parent be4e437f4d
commit a21b4a2d1a
6 changed files with 57 additions and 53 deletions

View File

@@ -1204,78 +1204,73 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
}
// Begin building the result string
wstringstream resultStream{};
wstring result;
// Make sure negative zeros aren't allowed.
if ((pnum->sign == -1) && (length > 0))
{
resultStream << L'-';
result = L'-';
}
if (exponent <= 0 && !useSciForm)
{
resultStream << L'0';
resultStream << g_decimalSeparator;
result += L'0';
result += g_decimalSeparator;
// Used up a digit unaccounted for.
}
while (exponent < 0)
{
resultStream << L'0';
result += L'0';
exponent++;
}
while (length > 0)
{
exponent--;
resultStream << DIGITS[*pmant--];
result += DIGITS[*pmant--];
length--;
// Be more regular in using a decimal point.
if (exponent == 0)
{
resultStream << g_decimalSeparator;
result += g_decimalSeparator;
}
}
while (exponent > 0)
{
resultStream << L'0';
result += L'0';
exponent--;
// Be more regular in using a decimal point.
if (exponent == 0)
{
resultStream << g_decimalSeparator;
result += g_decimalSeparator;
}
}
if (useSciForm)
{
resultStream << (radix == 10 ? L'e' : L'^');
resultStream << (eout < 0 ? L'-' : L'+');
result += (radix == 10 ? L'e' : L'^');
result += (eout < 0 ? L'-' : L'+');
eout = abs(eout);
wstringstream exponentStream{};
wstring expString{};
do
{
exponentStream << DIGITS[eout % radix];
expString += DIGITS[eout % radix];
eout /= radix;
} while (eout > 0);
auto expString = exponentStream.str();
for (auto ritr = expString.rbegin(); ritr != expString.rend(); ritr++)
{
resultStream << *ritr;
}
result.insert(result.end(), expString.crbegin(), expString.crend());
}
// Remove trailing decimal
auto resultString = resultStream.str();
if (!resultString.empty() && resultString.back() == g_decimalSeparator)
if (!result.empty() && result.back() == g_decimalSeparator)
{
resultString.pop_back();
result.pop_back();
}
return resultString;
return result;
}
//-----------------------------------------------------------------------------