From 2ee2583d3dcb759d263a03ac0969ab2cb2c31049 Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Sat, 9 Mar 2019 17:13:24 -0800 Subject: [PATCH] CurrencyConverter: - remove extra space at the end of the value with some locales and numbers - fix formatting issue --- src/CalcViewModel/UnitConverterViewModel.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CalcViewModel/UnitConverterViewModel.cpp b/src/CalcViewModel/UnitConverterViewModel.cpp index 393165eb..46553012 100644 --- a/src/CalcViewModel/UnitConverterViewModel.cpp +++ b/src/CalcViewModel/UnitConverterViewModel.cpp @@ -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 regexTrimSpacesEnd = wregex(L"\\s+$"); namespace CalculatorApp::ViewModel { @@ -348,10 +349,11 @@ String^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& str if (pos != wstring::npos) { currencyResult.erase(pos, currencyCode.length()); - pos = currencyResult.find(L'\u00a0'); // non-breaking space - if (pos != wstring::npos) + std::wsmatch sm; + if (regex_search(currencyResult, sm, regexTrimSpacesEnd)) { currencyResult.erase(pos, 1); + currencyResult.erase(sm.prefix().length(), sm.length()); } }