Skip to content

Commit

Permalink
ICU-21289 Switch to using CharString for calling uloc_toLanguageTag().
Browse files Browse the repository at this point in the history
  • Loading branch information
roubert committed Sep 26, 2023
1 parent 2df1ab7 commit 9bce52f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
7 changes: 5 additions & 2 deletions icu4c/source/common/locmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,9 +1200,12 @@ uprv_convertToLCIDPlatform(const char* localeID, UErrorCode* status)
}
}

char asciiBCP47Tag[LOCALE_NAME_MAX_LENGTH] = {};
// this will change it from de_DE@collation=phonebook to de-DE-u-co-phonebk form
(void)uloc_toLanguageTag(mylocaleID, asciiBCP47Tag, UPRV_LENGTHOF(asciiBCP47Tag), false, status);
icu::CharString asciiBCP47Tag;
{
icu::CharStringByteSink sink(&asciiBCP47Tag);
ulocimp_toLanguageTag(mylocaleID, sink, false, status);
}

if (U_SUCCESS(*status))
{
Expand Down
10 changes: 8 additions & 2 deletions icu4c/source/i18n/windtfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
#include "unicode/timezone.h"
#include "unicode/utmscale.h"

#include "bytesinkutil.h"
#include "charstr.h"
#include "cmemory.h"
#include "ulocimp.h"
#include "uresimp.h"
#include "windtfmt.h"
#include "wintzimpl.h"
Expand Down Expand Up @@ -99,10 +102,13 @@ UnicodeString* Win32DateFormat::getTimeDateFormat(const Calendar *cal, const Loc
static UErrorCode GetEquivalentWindowsLocaleName(const Locale& locale, UnicodeString** buffer)
{
UErrorCode status = U_ZERO_ERROR;
char asciiBCP47Tag[LOCALE_NAME_MAX_LENGTH] = {};

// Convert from names like "en_CA" and "de_DE@collation=phonebook" to "en-CA" and "de-DE-u-co-phonebk".
(void)uloc_toLanguageTag(locale.getName(), asciiBCP47Tag, UPRV_LENGTHOF(asciiBCP47Tag), false, &status);
CharString asciiBCP47Tag;
{
CharStringByteSink sink(&asciiBCP47Tag);
ulocimp_toLanguageTag(locale.getName(), sink, false, &status);
}

if (U_SUCCESS(status))
{
Expand Down
10 changes: 8 additions & 2 deletions icu4c/source/i18n/winnmfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
#include "unicode/locid.h"
#include "unicode/ustring.h"

#include "bytesinkutil.h"
#include "charstr.h"
#include "cmemory.h"
#include "uassert.h"
#include "ulocimp.h"
#include "locmap.h"

#ifndef WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -144,10 +147,13 @@ static void freeCurrencyFormat(CURRENCYFMTW *fmt)
static UErrorCode GetEquivalentWindowsLocaleName(const Locale& locale, UnicodeString** buffer)
{
UErrorCode status = U_ZERO_ERROR;
char asciiBCP47Tag[LOCALE_NAME_MAX_LENGTH] = {};

// Convert from names like "en_CA" and "de_DE@collation=phonebook" to "en-CA" and "de-DE-u-co-phonebk".
(void) uloc_toLanguageTag(locale.getName(), asciiBCP47Tag, UPRV_LENGTHOF(asciiBCP47Tag), false, &status);
CharString asciiBCP47Tag;
{
CharStringByteSink sink(&asciiBCP47Tag);
ulocimp_toLanguageTag(locale.getName(), sink, false, &status);
}

if (U_SUCCESS(status))
{
Expand Down

0 comments on commit 9bce52f

Please sign in to comment.