/* * Turns a string of the form "3;2;0" into the grouping UINT * needed for NUMBERFMT and CURRENCYFMT. If the string does not * end in ";0" then the return value should be multiplied by 10. * (e.g. "3" => 30, "3;2" => 320)
*/ static UINT getGrouping(constwchar_t *grouping)
{
UINT g = 0; constwchar_t *s;
for (s = grouping; *s != L'\0'; s += 1) { if (*s > L'0' && *s < L'9') {
g = g * 10 + (*s - L'0');
} elseif (*s != L';') { break;
}
}
// TODO: This is copied in both winnmfmt.cpp and windtfmt.cpp, but really should // be factored out into a common helper for both. static UErrorCode GetEquivalentWindowsLocaleName(const Locale& locale, UnicodeString** buffer)
{
UErrorCode status = U_ZERO_ERROR;
// Convert from names like "en_CA" and "de_DE@collation=phonebook" to "en-CA" and "de-DE-u-co-phonebk".
CharString asciiBCP47Tag = ulocimp_toLanguageTag(locale.getName(), false, status);
if (U_SUCCESS(status))
{ // Need it to be UTF-16, not 8-bit // TODO: This seems like a good thing for a helper wchar_t bcp47Tag[LOCALE_NAME_MAX_LENGTH] = {};
int32_t i; for (i = 0; i < UPRV_LENGTHOF(bcp47Tag); i++)
{ if (asciiBCP47Tag[i] == '\0')
{ break;
} else
{ // normally just copy the character
bcp47Tag[i] = static_cast<wchar_t>(asciiBCP47Tag[i]);
}
}
// Ensure it's null terminated if (i < (UPRV_LENGTHOF(bcp47Tag) - 1))
{
bcp47Tag[i] = L'\0';
} else
{ // Ran out of room.
bcp47Tag[UPRV_LENGTHOF(bcp47Tag) - 1] = L'\0';
}
// Note: On Windows versions below 10, there is no support for locale name aliases. // This means that it will fail for locales where ICU has a completely different // name (like ku vs ckb), and it will also not work for alternate sort locale // names like "de-DE-u-co-phonebk".
// TODO: We could add some sort of exception table for cases like ku vs ckb.
int length = ResolveLocaleName(bcp47Tag, windowsLocaleName, UPRV_LENGTHOF(windowsLocaleName));
if (length > 0)
{
*buffer = new UnicodeString(windowsLocaleName);
} else
{
status = U_UNSUPPORTED_ERROR;
}
} return status;
}
GetEquivalentWindowsLocaleName(locale, &fWindowsLocaleName); // Note: In the previous code, it would look up the LCID for the locale, and if // the locale was not recognized then it would get an LCID of 0, which is a // synonym for LOCALE_USER_DEFAULT on Windows. // If the above method fails, then fWindowsLocaleName will remain as nullptr, and // then we will pass nullptr to API GetLocaleInfoEx, which is the same as passing // LOCALE_USER_DEFAULT.
// Resolve actual locale to be used later
UErrorCode tmpsts = U_ZERO_ERROR; char tmpLocID[ULOC_FULLNAME_CAPACITY];
int32_t len = uloc_getLocaleForLCID(fLCID, tmpLocID, UPRV_LENGTHOF(tmpLocID) - 1, &tmpsts); if (U_SUCCESS(tmpsts)) {
tmpLocID[len] = 0;
fLocale = Locale((constchar*)tmpLocID);
}
constwchar_t *localeName = nullptr;
if (fWindowsLocaleName != nullptr)
{
localeName = reinterpret_cast<constwchar_t*>(toOldUCharPtr(fWindowsLocaleName->getTerminatedBuffer()));
}
/* Due to the arguments causing a result to be <= 23 characters (+2 for nullptr and minus),
we don't need to reallocate the buffer. */
va_start(args, fmt);
result = _vsnwprintf(nBuffer, STACK_BUFFER_SIZE, fmt, args);
va_end(args);
/* Just to make sure of the above statement, we add this assert */
U_ASSERT(result >=0); // The following code is not used because _vscwprintf isn't available on MinGW at the moment. /*if (result < 0) { int newLength;
// vswprintf is sensitive to the locale set by setlocale. For some locales // it doesn't use "." as the decimal separator, which is what GetNumberFormatW // and GetCurrencyFormatW both expect to see. // // To fix this, we scan over the string and replace the first non-digits, except // for a leading "-", with a "." // // Note: (nBuffer[0] == L'-') will evaluate to 1 if there is a leading '-' in the // number, and 0 otherwise. for (wchar_t *p = &nBuffer[nBuffer[0] == L'-']; *p != L'\0'; p += 1) { if (*p < L'0' || *p > L'9') {
*p = L'.'; break;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.