Compare locale strings, not their pointers (#183)

Change the stored locale type to wstring to make the comparison operator
work.
This commit is contained in:
Michał Janiszewski 2019-03-08 22:45:39 +01:00 committed by Daniel Belcher
parent 0197bf18c1
commit c85d7ec454

View File

@ -26,8 +26,9 @@ namespace CalculatorApp
m_digitSymbols.at(i) = formatter->FormatUInt(i)->Data()[0]; m_digitSymbols.at(i) = formatter->FormatUInt(i)->Data()[0];
} }
wchar_t resolvedName[LOCALE_NAME_MAX_LENGTH];
result = ResolveLocaleName(formatter->ResolvedLanguage->Data(), result = ResolveLocaleName(formatter->ResolvedLanguage->Data(),
m_resolvedName, resolvedName,
LOCALE_NAME_MAX_LENGTH); LOCALE_NAME_MAX_LENGTH);
if (result == 0) if (result == 0)
{ {
@ -35,8 +36,9 @@ namespace CalculatorApp
} }
else else
{ {
m_resolvedName = resolvedName;
wchar_t decimalString[LocaleSettingBufferSize] = L""; wchar_t decimalString[LocaleSettingBufferSize] = L"";
result = GetLocaleInfoEx(m_resolvedName, result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_SDECIMAL, LOCALE_SDECIMAL,
decimalString, decimalString,
ARRAYSIZE(decimalString)); ARRAYSIZE(decimalString));
@ -46,7 +48,7 @@ namespace CalculatorApp
} }
wchar_t groupingSymbolString[LocaleSettingBufferSize] = L""; wchar_t groupingSymbolString[LocaleSettingBufferSize] = L"";
result = GetLocaleInfoEx(m_resolvedName, result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_STHOUSAND, LOCALE_STHOUSAND,
groupingSymbolString, groupingSymbolString,
ARRAYSIZE(groupingSymbolString)); ARRAYSIZE(groupingSymbolString));
@ -56,7 +58,7 @@ namespace CalculatorApp
} }
wchar_t numberGroupingString[LocaleSettingBufferSize] = L""; wchar_t numberGroupingString[LocaleSettingBufferSize] = L"";
result = GetLocaleInfoEx(m_resolvedName, result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_SGROUPING, LOCALE_SGROUPING,
numberGroupingString, numberGroupingString,
ARRAYSIZE(numberGroupingString)); ARRAYSIZE(numberGroupingString));
@ -77,7 +79,7 @@ namespace CalculatorApp
} }
int currencyTrailingDigits = 0; int currencyTrailingDigits = 0;
result = GetLocaleInfoEx(m_resolvedName, result = GetLocaleInfoEx(m_resolvedName.c_str(),
LOCALE_ICURRDIGITS | LOCALE_RETURN_NUMBER, LOCALE_ICURRDIGITS | LOCALE_RETURN_NUMBER,
(LPWSTR)&currencyTrailingDigits, (LPWSTR)&currencyTrailingDigits,
sizeof(currencyTrailingDigits) / sizeof(WCHAR)); sizeof(currencyTrailingDigits) / sizeof(WCHAR));
@ -147,7 +149,7 @@ namespace CalculatorApp
Platform::String^ GetLocaleName() const Platform::String^ GetLocaleName() const
{ {
return ref new Platform::String(m_resolvedName); return ref new Platform::String(m_resolvedName.c_str());
} }
bool IsDigitEnUsSetting() const bool IsDigitEnUsSetting() const
@ -377,7 +379,7 @@ namespace CalculatorApp
Platform::String^ m_calendarIdentifier; Platform::String^ m_calendarIdentifier;
Windows::Globalization::DayOfWeek m_firstDayOfWeek; Windows::Globalization::DayOfWeek m_firstDayOfWeek;
int m_currencySymbolPrecedence; int m_currencySymbolPrecedence;
wchar_t m_resolvedName[LOCALE_NAME_MAX_LENGTH]; std::wstring m_resolvedName;
int m_currencyTrailingDigits; int m_currencyTrailingDigits;
static const unsigned int LocaleSettingBufferSize = 16; static const unsigned int LocaleSettingBufferSize = 16;
}; };