Trim the beginning of the string too

This commit is contained in:
Rudy Huyn 2019-03-09 17:29:51 -08:00
commit 9672f6df2b

View file

@ -53,6 +53,7 @@ constexpr size_t SELECTED_TARGET_UNIT = 2;
// x millisecond delay before we consider conversion to be final
constexpr unsigned int CONVERSION_FINALIZED_DELAY_IN_MS = 1000;
const wregex regexTrimSpacesStart = wregex(L"^\\s+");
const wregex regexTrimSpacesEnd = wregex(L"\\s+$");
namespace CalculatorApp::ViewModel
@ -350,9 +351,13 @@ String^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& str
{
currencyResult.erase(pos, currencyCode.length());
std::wsmatch sm;
if (regex_search(currencyResult, sm, regexTrimSpacesStart))
{
currencyResult.erase(sm.prefix().length(), sm.length());
}
if (regex_search(currencyResult, sm, regexTrimSpacesEnd))
{
currencyResult.erase(pos, 1);
currencyResult.erase(sm.prefix().length(), sm.length());
}
}