Skip to content

Commit

Permalink
Compare locale strings, not their pointers (microsoft#183)
Browse files Browse the repository at this point in the history
Change the stored locale type to wstring to make the comparison operator
work.
  • Loading branch information
janisozaur authored and Daniel Belcher committed Mar 8, 2019
1 parent 0197bf1 commit c85d7ec
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/CalcViewModel/Common/LocalizationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ namespace CalculatorApp
m_digitSymbols.at(i) = formatter->FormatUInt(i)->Data()[0];
}

wchar_t resolvedName[LOCALE_NAME_MAX_LENGTH];
result = ResolveLocaleName(formatter->ResolvedLanguage->Data(),
m_resolvedName,
resolvedName,
LOCALE_NAME_MAX_LENGTH);
if (result == 0)
{
throw std::runtime_error("Unexpected error resolving locale name");
}
else
{
m_resolvedName = resolvedName;
wchar_t decimalString[LocaleSettingBufferSize] = L"";
result = GetLocaleInfoEx(m_resolvedName,
result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_SDECIMAL,
decimalString,
ARRAYSIZE(decimalString));
Expand All @@ -46,7 +48,7 @@ namespace CalculatorApp
}

wchar_t groupingSymbolString[LocaleSettingBufferSize] = L"";
result = GetLocaleInfoEx(m_resolvedName,
result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_STHOUSAND,
groupingSymbolString,
ARRAYSIZE(groupingSymbolString));
Expand All @@ -56,7 +58,7 @@ namespace CalculatorApp
}

wchar_t numberGroupingString[LocaleSettingBufferSize] = L"";
result = GetLocaleInfoEx(m_resolvedName,
result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_SGROUPING,
numberGroupingString,
ARRAYSIZE(numberGroupingString));
Expand All @@ -77,7 +79,7 @@ namespace CalculatorApp
}

int currencyTrailingDigits = 0;
result = GetLocaleInfoEx(m_resolvedName,
result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_ICURRDIGITS | LOCALE_RETURN_NUMBER,
(LPWSTR)&currencyTrailingDigits,
sizeof(currencyTrailingDigits) / sizeof(WCHAR));
Expand Down Expand Up @@ -147,7 +149,7 @@ namespace CalculatorApp

Platform::String^ GetLocaleName() const
{
return ref new Platform::String(m_resolvedName);
return ref new Platform::String(m_resolvedName.c_str());
}

bool IsDigitEnUsSetting() const
Expand Down Expand Up @@ -377,7 +379,7 @@ namespace CalculatorApp
Platform::String^ m_calendarIdentifier;
Windows::Globalization::DayOfWeek m_firstDayOfWeek;
int m_currencySymbolPrecedence;
wchar_t m_resolvedName[LOCALE_NAME_MAX_LENGTH];
std::wstring m_resolvedName;
int m_currencyTrailingDigits;
static const unsigned int LocaleSettingBufferSize = 16;
};
Expand Down

0 comments on commit c85d7ec

Please sign in to comment.