Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ab67f53

Browse files
authored
Fix ICU errors by porting over dotnet/runtime#47346 (#28163)
1 parent 49b0882 commit ab67f53

File tree

9 files changed

+124
-116
lines changed

9 files changed

+124
-116
lines changed

src/corefx/System.Globalization.Native/pal_calendarData.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <assert.h>
66
#include <stdlib.h>
7+
#include <stdbool.h>
78
#include <string.h>
89
#include <strings.h>
910

@@ -115,8 +116,8 @@ int32_t GlobalizationNative_GetCalendars(
115116
{
116117
UErrorCode err = U_ZERO_ERROR;
117118
char locale[ULOC_FULLNAME_CAPACITY];
118-
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
119-
UEnumeration* pEnum = ucal_getKeywordValuesForLocale("calendar", locale, TRUE, &err);
119+
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
120+
UEnumeration* pEnum = ucal_getKeywordValuesForLocale("calendar", locale, true, &err);
120121
int stringEnumeratorCount = uenum_count(pEnum, &err);
121122
int calendarsReturned = 0;
122123
for (int i = 0; i < stringEnumeratorCount && calendarsReturned < calendarsCapacity; i++)
@@ -186,7 +187,7 @@ ResultCode GlobalizationNative_GetCalendarInfo(
186187
{
187188
UErrorCode err = U_ZERO_ERROR;
188189
char locale[ULOC_FULLNAME_CAPACITY];
189-
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
190+
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
190191

191192
if (U_FAILURE(err))
192193
return UnknownError;
@@ -198,7 +199,7 @@ ResultCode GlobalizationNative_GetCalendarInfo(
198199
case CalendarData_MonthDay:
199200
return GetMonthDayPattern(locale, result, resultCapacity);
200201
default:
201-
assert(FALSE);
202+
assert(false);
202203
return UnknownError;
203204
}
204205
}
@@ -219,19 +220,19 @@ static int InvokeCallbackForDatePattern(const char* locale,
219220
UDateFormat* pFormat = udat_open(UDAT_NONE, style, locale, NULL, 0, NULL, 0, &err);
220221

221222
if (U_FAILURE(err))
222-
return FALSE;
223+
return false;
223224

224225
UErrorCode ignore = U_ZERO_ERROR;
225-
int32_t patternLen = udat_toPattern(pFormat, FALSE, NULL, 0, &ignore) + 1;
226+
int32_t patternLen = udat_toPattern(pFormat, false, NULL, 0, &ignore) + 1;
226227

227228
UChar* pattern = calloc(patternLen, sizeof(UChar));
228229
if (pattern == NULL)
229230
{
230231
udat_close(pFormat);
231-
return FALSE;
232+
return false;
232233
}
233234

234-
udat_toPattern(pFormat, FALSE, pattern, patternLen, &err);
235+
udat_toPattern(pFormat, false, pattern, patternLen, &err);
235236
udat_close(pFormat);
236237

237238
if (U_SUCCESS(err))
@@ -259,7 +260,7 @@ static int InvokeCallbackForDateTimePattern(const char* locale,
259260
UDateTimePatternGenerator* pGenerator = udatpg_open(locale, &err);
260261

261262
if (U_FAILURE(err))
262-
return FALSE;
263+
return false;
263264

264265
UErrorCode ignore = U_ZERO_ERROR;
265266
int32_t patternLen = udatpg_getBestPattern(pGenerator, patternSkeleton, -1, NULL, 0, &ignore) + 1;
@@ -268,7 +269,7 @@ static int InvokeCallbackForDateTimePattern(const char* locale,
268269
if (bestPattern == NULL)
269270
{
270271
udatpg_close(pGenerator);
271-
return FALSE;
272+
return false;
272273
}
273274

274275
udatpg_getBestPattern(pGenerator, patternSkeleton, -1, bestPattern, patternLen, &err);
@@ -301,7 +302,7 @@ static int32_t EnumSymbols(const char* locale,
301302
UDateFormat* pFormat = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, locale, NULL, 0, NULL, 0, &err);
302303

303304
if (U_FAILURE(err))
304-
return FALSE;
305+
return false;
305306

306307
char localeWithCalendarName[ULOC_FULLNAME_CAPACITY];
307308
strncpy(localeWithCalendarName, locale, ULOC_FULLNAME_CAPACITY);
@@ -314,7 +315,7 @@ static int32_t EnumSymbols(const char* locale,
314315
if (U_FAILURE(err))
315316
{
316317
udat_close(pFormat);
317-
return FALSE;
318+
return false;
318319
}
319320

320321
udat_setCalendar(pFormat, pCalendar);
@@ -416,7 +417,7 @@ static int32_t EnumAbbrevEraNames(const char* locale,
416417
strncpy(localeNamePtr, locale, ULOC_FULLNAME_CAPACITY);
417418
localeNamePtr[ULOC_FULLNAME_CAPACITY - 1] = 0;
418419

419-
while (TRUE)
420+
while (true)
420421
{
421422
UErrorCode status = U_ZERO_ERROR;
422423
const char* name = GetCalendarName(calendarId);
@@ -431,7 +432,7 @@ static int32_t EnumAbbrevEraNames(const char* locale,
431432
{
432433
EnumUResourceBundle(erasResBundle, callback, context);
433434
CloseResBundle(rootResBundle, calResBundle, targetCalResBundle, erasColResBundle, erasResBundle);
434-
return TRUE;
435+
return true;
435436
}
436437

437438
// Couldn't find the data we need for this locale, we should fallback.
@@ -484,10 +485,10 @@ int32_t GlobalizationNative_EnumCalendarInfo(EnumCalendarInfoCallback callback,
484485
{
485486
UErrorCode err = U_ZERO_ERROR;
486487
char locale[ULOC_FULLNAME_CAPACITY];
487-
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
488+
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
488489

489490
if (U_FAILURE(err))
490-
return FALSE;
491+
return false;
491492

492493
switch (dataType)
493494
{
@@ -528,8 +529,8 @@ int32_t GlobalizationNative_EnumCalendarInfo(EnumCalendarInfoCallback callback,
528529
case CalendarData_AbbrevEraNames:
529530
return EnumAbbrevEraNames(locale, calendarId, callback, context);
530531
default:
531-
assert(FALSE);
532-
return FALSE;
532+
assert(false);
533+
return false;
533534
}
534535
}
535536

@@ -573,7 +574,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era,
573574
UCalendar* pCal = ucal_open(NULL, 0, JAPANESE_LOCALE_AND_CALENDAR, UCAL_TRADITIONAL, &err);
574575

575576
if (U_FAILURE(err))
576-
return FALSE;
577+
return false;
577578

578579
ucal_set(pCal, UCAL_ERA, era);
579580
ucal_set(pCal, UCAL_YEAR, 1);
@@ -583,7 +584,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era,
583584
if (U_FAILURE(err))
584585
{
585586
ucal_close(pCal);
586-
return FALSE;
587+
return false;
587588
}
588589

589590
// set the date to Jan 1
@@ -620,5 +621,5 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era,
620621
}
621622

622623
ucal_close(pCal);
623-
return FALSE;
624+
return false;
624625
}

src/corefx/System.Globalization.Native/pal_casing.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <assert.h>
77
#include <stdint.h>
8+
#include <stdbool.h>
89

910
#include "pal_casing.h"
1011
#include "pal_icushim.h"
@@ -29,7 +30,7 @@ void GlobalizationNative_ChangeCase(
2930
// compiler wasn't doing that optimization, and it results in an ~15-20% perf
3031
// improvement on longer strings.)
3132

32-
UBool isError = FALSE;
33+
UBool isError = false;
3334
int32_t srcIdx = 0, dstIdx = 0;
3435
UChar32 srcCodepoint, dstCodepoint;
3536

@@ -40,7 +41,7 @@ void GlobalizationNative_ChangeCase(
4041
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
4142
dstCodepoint = u_toupper(srcCodepoint);
4243
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
43-
assert(isError == FALSE && srcIdx == dstIdx);
44+
assert(isError == false && srcIdx == dstIdx);
4445
}
4546
}
4647
else
@@ -50,7 +51,7 @@ void GlobalizationNative_ChangeCase(
5051
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
5152
dstCodepoint = u_tolower(srcCodepoint);
5253
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
53-
assert(isError == FALSE && srcIdx == dstIdx);
54+
assert(isError == false && srcIdx == dstIdx);
5455
}
5556
}
5657
}
@@ -68,7 +69,7 @@ void GlobalizationNative_ChangeCaseInvariant(
6869
{
6970
// See algorithmic comment in ChangeCase.
7071

71-
UBool isError = FALSE;
72+
UBool isError = false;
7273
int32_t srcIdx = 0, dstIdx = 0;
7374
UChar32 srcCodepoint, dstCodepoint;
7475

@@ -82,7 +83,7 @@ void GlobalizationNative_ChangeCaseInvariant(
8283
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
8384
dstCodepoint = ((srcCodepoint == (UChar32)0x0131) ? (UChar32)0x0131 : u_toupper(srcCodepoint));
8485
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
85-
assert(isError == FALSE && srcIdx == dstIdx);
86+
assert(isError == false && srcIdx == dstIdx);
8687
}
8788
}
8889
else
@@ -95,7 +96,7 @@ void GlobalizationNative_ChangeCaseInvariant(
9596
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
9697
dstCodepoint = ((srcCodepoint == (UChar32)0x0130) ? (UChar32)0x0130 : u_tolower(srcCodepoint));
9798
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
98-
assert(isError == FALSE && srcIdx == dstIdx);
99+
assert(isError == false && srcIdx == dstIdx);
99100
}
100101
}
101102
}
@@ -112,7 +113,7 @@ void GlobalizationNative_ChangeCaseTurkish(
112113
{
113114
// See algorithmic comment in ChangeCase.
114115

115-
UBool isError = FALSE;
116+
UBool isError = false;
116117
int32_t srcIdx = 0, dstIdx = 0;
117118
UChar32 srcCodepoint, dstCodepoint;
118119

@@ -125,7 +126,7 @@ void GlobalizationNative_ChangeCaseTurkish(
125126
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
126127
dstCodepoint = ((srcCodepoint == (UChar32)0x0069) ? (UChar32)0x0130 : u_toupper(srcCodepoint));
127128
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
128-
assert(isError == FALSE && srcIdx == dstIdx);
129+
assert(isError == false && srcIdx == dstIdx);
129130
}
130131
}
131132
else
@@ -137,7 +138,7 @@ void GlobalizationNative_ChangeCaseTurkish(
137138
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
138139
dstCodepoint = ((srcCodepoint == (UChar32)0x0049) ? (UChar32)0x0131 : u_tolower(srcCodepoint));
139140
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
140-
assert(isError == FALSE && srcIdx == dstIdx);
141+
assert(isError == false && srcIdx == dstIdx);
141142
}
142143
}
143144
}

src/corefx/System.Globalization.Native/pal_collation.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static UCharList* GetCustomRules(int32_t options, UColAttributeValue strength, i
157157

158158
// If we need to create customRules, the KanaType custom rule will be 88 kana characters * 4 = 352 chars long
159159
// and the Width custom rule will be at most 212 halfwidth characters * 5 = 1060 chars long.
160-
int capacity =
160+
int capacity =
161161
((needsIgnoreKanaTypeCustomRule || needsNotIgnoreKanaTypeCustomRule) ? 4 * (hiraganaEnd - hiraganaStart + 1) : 0) +
162162
((needsIgnoreWidthCustomRule || needsNotIgnoreWidthCustomRule) ? 5 * g_HalfFullCharsLength : 0);
163163

@@ -306,10 +306,10 @@ UCollator* CloneCollatorWithOptions(const UCollator* pCollator, int32_t options,
306306
return pClonedCollator;
307307
}
308308

309-
// Returns TRUE if all the collation elements in str are completely ignorable
309+
// Returns true if all the collation elements in str are completely ignorable
310310
static int CanIgnoreAllCollationElements(const UCollator* pColl, const UChar* lpStr, int32_t length)
311311
{
312-
int result = TRUE;
312+
int result = true;
313313
UErrorCode err = U_ZERO_ERROR;
314314
UCollationElements* pCollElem = ucol_openElements(pColl, lpStr, length, &err);
315315

@@ -320,15 +320,15 @@ static int CanIgnoreAllCollationElements(const UCollator* pColl, const UChar* lp
320320
{
321321
if (curCollElem != 0)
322322
{
323-
result = FALSE;
323+
result = false;
324324
break;
325325
}
326326
}
327327

328328
ucol_closeElements(pCollElem);
329329
}
330330

331-
return U_SUCCESS(err) ? result : FALSE;
331+
return U_SUCCESS(err) ? result : false;
332332

333333
}
334334

@@ -422,7 +422,7 @@ int32_t GlobalizationNative_GetSortVersion(SortHandle* pSortHandle)
422422
}
423423
else
424424
{
425-
assert(FALSE && "Unexpected ucol_getVersion to fail.");
425+
assert(false && "Unexpected ucol_getVersion to fail.");
426426

427427
// we didn't use UCOL_TAILORINGS_VERSION because it is deprecated in ICU v5
428428
result = UCOL_RUNTIME_VERSION << 16 | UCOL_BUILDER_VERSION;
@@ -527,15 +527,15 @@ static int AreEqualOrdinalIgnoreCase(UChar32 one, UChar32 two)
527527

528528
if (one == two)
529529
{
530-
return TRUE;
530+
return true;
531531
}
532532

533533
if (one == 0x0131 || two == 0x0131)
534534
{
535535
// On Windows with InvariantCulture, the LATIN SMALL LETTER DOTLESS I (U+0131)
536536
// capitalizes to itself, whereas with ICU it capitalizes to LATIN CAPITAL LETTER I (U+0049).
537537
// We special case it to match the Windows invariant behavior.
538-
return FALSE;
538+
return false;
539539
}
540540

541541
return u_toupper(one) == u_toupper(two);
@@ -560,19 +560,19 @@ int32_t GlobalizationNative_IndexOfOrdinalIgnoreCase(
560560
const UChar *src = lpSource, *trg = lpTarget;
561561
UChar32 srcCodepoint, trgCodepoint;
562562

563-
int32_t match = TRUE;
563+
int32_t match = true;
564564
while (trgIdx < cwTargetLength)
565565
{
566566
U16_NEXT(src, srcIdx, cwSourceLength, srcCodepoint);
567567
U16_NEXT(trg, trgIdx, cwTargetLength, trgCodepoint);
568568
if (!AreEqualOrdinalIgnoreCase(srcCodepoint, trgCodepoint))
569569
{
570-
match = FALSE;
570+
match = false;
571571
break;
572572
}
573573
}
574574

575-
if (match)
575+
if (match)
576576
{
577577
result = i;
578578
if (!findLast)
@@ -598,7 +598,7 @@ int32_t GlobalizationNative_StartsWith(
598598
int32_t cwSourceLength,
599599
int32_t options)
600600
{
601-
int32_t result = FALSE;
601+
int32_t result = false;
602602
UErrorCode err = U_ZERO_ERROR;
603603
const UCollator* pColl = GetCollatorFromSortHandle(pSortHandle, options, &err);
604604

@@ -614,7 +614,7 @@ int32_t GlobalizationNative_StartsWith(
614614
{
615615
if (idx == 0)
616616
{
617-
result = TRUE;
617+
result = true;
618618
}
619619
else
620620
{
@@ -640,7 +640,7 @@ int32_t GlobalizationNative_EndsWith(
640640
int32_t cwSourceLength,
641641
int32_t options)
642642
{
643-
int32_t result = FALSE;
643+
int32_t result = false;
644644
UErrorCode err = U_ZERO_ERROR;
645645
const UCollator* pColl = GetCollatorFromSortHandle(pSortHandle, options, &err);
646646

@@ -657,7 +657,7 @@ int32_t GlobalizationNative_EndsWith(
657657
{
658658
if ((idx + usearch_getMatchedLength(pSearch)) == cwSourceLength)
659659
{
660-
result = TRUE;
660+
result = true;
661661
}
662662
else
663663
{

0 commit comments

Comments
 (0)