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

Commit c152ba9

Browse files
committed
Fix inconsistent usage of various bool types
Convert u_charsToUChars_safe to ICU style error handling Unify error handling code across functions to use the same patterns Add static modifier to functions that are used only from single C file
1 parent 5875f89 commit c152ba9

File tree

8 files changed

+249
-258
lines changed

8 files changed

+249
-258
lines changed

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

Lines changed: 68 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ GetCalendarName
3131
3232
Gets the associated ICU calendar name for the CalendarId.
3333
*/
34-
const char* GetCalendarName(CalendarId calendarId)
34+
static const char* GetCalendarName(CalendarId calendarId)
3535
{
3636
switch (calendarId)
3737
{
@@ -79,7 +79,7 @@ GetCalendarId
7979
8080
Gets the associated CalendarId for the ICU calendar name.
8181
*/
82-
CalendarId GetCalendarId(const char* calendarName)
82+
static CalendarId GetCalendarId(const char* calendarName)
8383
{
8484
if (strcasecmp(calendarName, GREGORIAN_NAME) == 0)
8585
// TODO: what about the other gregorian types?
@@ -115,7 +115,7 @@ int32_t GlobalizationNative_GetCalendars(
115115
{
116116
UErrorCode err = U_ZERO_ERROR;
117117
char locale[ULOC_FULLNAME_CAPACITY];
118-
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
118+
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
119119
UEnumeration* pEnum = ucal_getKeywordValuesForLocale("calendar", locale, TRUE, &err);
120120
int stringEnumeratorCount = uenum_count(pEnum, &err);
121121
int calendarsReturned = 0;
@@ -143,7 +143,9 @@ GetMonthDayPattern
143143
144144
Gets the Month-Day DateTime pattern for the specified locale.
145145
*/
146-
ResultCode GetMonthDayPattern(const char* locale, UChar* sMonthDay, int32_t stringCapacity)
146+
static ResultCode GetMonthDayPattern(const char* locale,
147+
UChar* sMonthDay,
148+
int32_t stringCapacity)
147149
{
148150
UErrorCode err = U_ZERO_ERROR;
149151
UDateTimePatternGenerator* pGenerator = udatpg_open(locale, &err);
@@ -158,7 +160,10 @@ GetNativeCalendarName
158160
159161
Gets the native calendar name.
160162
*/
161-
ResultCode GetNativeCalendarName(const char* locale, CalendarId calendarId, UChar* nativeName, int32_t stringCapacity)
163+
static ResultCode GetNativeCalendarName(const char* locale,
164+
CalendarId calendarId,
165+
UChar* nativeName,
166+
int32_t stringCapacity)
162167
{
163168
UErrorCode err = U_ZERO_ERROR;
164169
ULocaleDisplayNames* pDisplayNames = uldn_open(locale, ULDN_STANDARD_NAMES, &err);
@@ -181,7 +186,7 @@ ResultCode GlobalizationNative_GetCalendarInfo(
181186
{
182187
UErrorCode err = U_ZERO_ERROR;
183188
char locale[ULOC_FULLNAME_CAPACITY];
184-
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
189+
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
185190

186191
if (U_FAILURE(err))
187192
return UnknownError;
@@ -193,7 +198,7 @@ ResultCode GlobalizationNative_GetCalendarInfo(
193198
case MonthDay:
194199
return GetMonthDayPattern(locale, result, resultCapacity);
195200
default:
196-
assert(false);
201+
assert(FALSE);
197202
return UnknownError;
198203
}
199204
}
@@ -205,28 +210,28 @@ InvokeCallbackForDatePattern
205210
Gets the ICU date pattern for the specified locale and EStyle and invokes the
206211
callback with the result.
207212
*/
208-
bool InvokeCallbackForDatePattern(const char* locale,
209-
UDateFormatStyle style,
210-
EnumCalendarInfoCallback callback,
211-
const void* context)
213+
static int InvokeCallbackForDatePattern(const char* locale,
214+
UDateFormatStyle style,
215+
EnumCalendarInfoCallback callback,
216+
const void* context)
212217
{
213218
UErrorCode err = U_ZERO_ERROR;
214219
UDateFormat* pFormat = udat_open(UDAT_NONE, style, locale, NULL, 0, NULL, 0, &err);
215220

216221
if (U_FAILURE(err))
217-
return false;
222+
return FALSE;
218223

219224
UErrorCode ignore = U_ZERO_ERROR;
220-
int32_t patternLen = udat_toPattern(pFormat, false, NULL, 0, &ignore) + 1;
225+
int32_t patternLen = udat_toPattern(pFormat, FALSE, NULL, 0, &ignore) + 1;
221226

222227
UChar* pattern = calloc(patternLen, sizeof(UChar));
223228
if (pattern == NULL)
224229
{
225230
udat_close(pFormat);
226-
return false;
231+
return FALSE;
227232
}
228233

229-
udat_toPattern(pFormat, false, pattern, patternLen, &err);
234+
udat_toPattern(pFormat, FALSE, pattern, patternLen, &err);
230235
udat_close(pFormat);
231236

232237
if (U_SUCCESS(err))
@@ -235,7 +240,7 @@ bool InvokeCallbackForDatePattern(const char* locale,
235240
}
236241

237242
free(pattern);
238-
return U_SUCCESS(err);
243+
return UErrorCodeToBool(err);
239244
}
240245

241246
/*
@@ -245,16 +250,16 @@ InvokeCallbackForDateTimePattern
245250
Gets the DateTime pattern for the specified skeleton and invokes the callback
246251
with the retrieved value.
247252
*/
248-
bool InvokeCallbackForDateTimePattern(const char* locale,
249-
const UChar* patternSkeleton,
250-
EnumCalendarInfoCallback callback,
251-
const void* context)
253+
static int InvokeCallbackForDateTimePattern(const char* locale,
254+
const UChar* patternSkeleton,
255+
EnumCalendarInfoCallback callback,
256+
const void* context)
252257
{
253258
UErrorCode err = U_ZERO_ERROR;
254259
UDateTimePatternGenerator* pGenerator = udatpg_open(locale, &err);
255260

256261
if (U_FAILURE(err))
257-
return false;
262+
return FALSE;
258263

259264
UErrorCode ignore = U_ZERO_ERROR;
260265
int32_t patternLen = udatpg_getBestPattern(pGenerator, patternSkeleton, -1, NULL, 0, &ignore) + 1;
@@ -263,7 +268,7 @@ bool InvokeCallbackForDateTimePattern(const char* locale,
263268
if (bestPattern == NULL)
264269
{
265270
udatpg_close(pGenerator);
266-
return false;
271+
return FALSE;
267272
}
268273

269274
udatpg_getBestPattern(pGenerator, patternSkeleton, -1, bestPattern, patternLen, &err);
@@ -275,7 +280,7 @@ bool InvokeCallbackForDateTimePattern(const char* locale,
275280
}
276281

277282
free(bestPattern);
278-
return U_SUCCESS(err);
283+
return UErrorCodeToBool(err);
279284
}
280285

281286
/*
@@ -285,35 +290,29 @@ EnumSymbols
285290
Enumerates all of the symbols of a type for a locale and calendar and invokes a callback
286291
for each value.
287292
*/
288-
bool EnumSymbols(const char* locale,
289-
CalendarId calendarId,
290-
UDateFormatSymbolType type,
291-
int32_t startIndex,
292-
EnumCalendarInfoCallback callback,
293-
const void* context)
293+
static int32_t EnumSymbols(const char* locale,
294+
CalendarId calendarId,
295+
UDateFormatSymbolType type,
296+
int32_t startIndex,
297+
EnumCalendarInfoCallback callback,
298+
const void* context)
294299
{
295300
UErrorCode err = U_ZERO_ERROR;
296301
UDateFormat* pFormat = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, locale, NULL, 0, NULL, 0, &err);
297302

298303
if (U_FAILURE(err))
299-
return false;
304+
return FALSE;
300305

301306
char localeWithCalendarName[ULOC_FULLNAME_CAPACITY];
302307
strncpy(localeWithCalendarName, locale, ULOC_FULLNAME_CAPACITY);
303308
uloc_setKeywordValue("calendar", GetCalendarName(calendarId), localeWithCalendarName, ULOC_FULLNAME_CAPACITY, &err);
304309

305-
if (U_FAILURE(err))
306-
{
307-
udat_close(pFormat);
308-
return false;
309-
}
310-
311310
UCalendar* pCalendar = ucal_open(NULL, 0, localeWithCalendarName, UCAL_DEFAULT, &err);
312311

313312
if (U_FAILURE(err))
314313
{
315314
udat_close(pFormat);
316-
return false;
315+
return FALSE;
317316
}
318317

319318
udat_setCalendar(pFormat, pCalendar);
@@ -356,10 +355,12 @@ bool EnumSymbols(const char* locale,
356355

357356
udat_close(pFormat);
358357
ucal_close(pCalendar);
359-
return U_SUCCESS(err);
358+
return UErrorCodeToBool(err);
360359
}
361360

362-
bool EnumUResourceBundle(const UResourceBundle* bundle, EnumCalendarInfoCallback callback, const void* context)
361+
static void EnumUResourceBundle(const UResourceBundle* bundle,
362+
EnumCalendarInfoCallback callback,
363+
const void* context)
363364
{
364365
int32_t eraNameCount = ures_getSize(bundle);
365366

@@ -374,15 +375,13 @@ bool EnumUResourceBundle(const UResourceBundle* bundle, EnumCalendarInfoCallback
374375
callback(eraName, context);
375376
}
376377
}
377-
378-
return true;
379378
}
380379

381-
void CloseResBundle(const UResourceBundle* rootResBundle,
382-
const UResourceBundle* calResBundle,
383-
const UResourceBundle* targetCalResBundle,
384-
const UResourceBundle* erasColResBundle,
385-
const UResourceBundle* erasResBundle)
380+
static void CloseResBundle(const UResourceBundle* rootResBundle,
381+
const UResourceBundle* calResBundle,
382+
const UResourceBundle* targetCalResBundle,
383+
const UResourceBundle* erasColResBundle,
384+
const UResourceBundle* erasResBundle)
386385
{
387386
ures_close(rootResBundle);
388387
ures_close(calResBundle);
@@ -398,10 +397,10 @@ EnumAbbrevEraNames
398397
Enumerates all the abbreviated era names of the specified locale and calendar, invoking the
399398
callback function for each era name.
400399
*/
401-
bool EnumAbbrevEraNames(const char* locale,
402-
CalendarId calendarId,
403-
EnumCalendarInfoCallback callback,
404-
const void* context)
400+
static int32_t EnumAbbrevEraNames(const char* locale,
401+
CalendarId calendarId,
402+
EnumCalendarInfoCallback callback,
403+
const void* context)
405404
{
406405
// The C-API for ICU provides no way to get at the abbreviated era names for a calendar (so we can't use EnumSymbols
407406
// here). Instead we will try to walk the ICU resource tables directly and fall back to regular era names if can't
@@ -414,7 +413,7 @@ bool EnumAbbrevEraNames(const char* locale,
414413

415414
strncpy(localeNamePtr, locale, ULOC_FULLNAME_CAPACITY);
416415

417-
while (true)
416+
while (TRUE)
418417
{
419418
UErrorCode status = U_ZERO_ERROR;
420419
char* name = GetCalendarName(calendarId);
@@ -429,7 +428,7 @@ bool EnumAbbrevEraNames(const char* locale,
429428
{
430429
EnumUResourceBundle(erasResBundle, callback, context);
431430
CloseResBundle(rootResBundle, calResBundle, targetCalResBundle, erasColResBundle, erasResBundle);
432-
return true;
431+
return TRUE;
433432
}
434433

435434
// Couldn't find the data we need for this locale, we should fallback.
@@ -474,19 +473,18 @@ Allows for a collection of calendar string data to be retrieved by invoking
474473
the callback for each value in the collection.
475474
The context parameter is passed through to the callback along with each string.
476475
*/
477-
int32_t GlobalizationNative_EnumCalendarInfo(
478-
EnumCalendarInfoCallback callback,
479-
const UChar* localeName,
480-
CalendarId calendarId,
481-
CalendarDataType dataType,
482-
const void* context)
476+
int32_t GlobalizationNative_EnumCalendarInfo(EnumCalendarInfoCallback callback,
477+
const UChar* localeName,
478+
CalendarId calendarId,
479+
CalendarDataType dataType,
480+
const void* context)
483481
{
484482
UErrorCode err = U_ZERO_ERROR;
485483
char locale[ULOC_FULLNAME_CAPACITY];
486-
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
484+
GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
487485

488486
if (U_FAILURE(err))
489-
return false;
487+
return FALSE;
490488

491489
switch (dataType)
492490
{
@@ -527,8 +525,8 @@ int32_t GlobalizationNative_EnumCalendarInfo(
527525
case AbbrevEraNames:
528526
return EnumAbbrevEraNames(locale, calendarId, callback, context);
529527
default:
530-
assert(false);
531-
return false;
528+
assert(FALSE);
529+
return FALSE;
532530
}
533531
}
534532

@@ -559,8 +557,10 @@ GetJapaneseEraInfo
559557
560558
Gets the starting Gregorian date of the specified Japanese Era.
561559
*/
562-
int32_t GlobalizationNative_GetJapaneseEraStartDate(
563-
int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay)
560+
int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era,
561+
int32_t* startYear,
562+
int32_t* startMonth,
563+
int32_t* startDay)
564564
{
565565
*startYear = -1;
566566
*startMonth = -1;
@@ -570,7 +570,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(
570570
UCalendar* pCal = ucal_open(NULL, 0, JAPANESE_LOCALE_AND_CALENDAR, UCAL_TRADITIONAL, &err);
571571

572572
if (U_FAILURE(err))
573-
return false;
573+
return FALSE;
574574

575575
ucal_set(pCal, UCAL_ERA, era);
576576
ucal_set(pCal, UCAL_YEAR, 1);
@@ -580,7 +580,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(
580580
if (U_FAILURE(err))
581581
{
582582
ucal_close(pCal);
583-
return false;
583+
return FALSE;
584584
}
585585

586586
// set the date to Jan 1
@@ -607,7 +607,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(
607607
*startDay = ucal_get(pCal, UCAL_DATE, &err);
608608
ucal_close(pCal);
609609

610-
return U_SUCCESS(err);
610+
return UErrorCodeToBool(err);
611611
}
612612
}
613613
}
@@ -617,5 +617,5 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(
617617
}
618618

619619
ucal_close(pCal);
620-
return false;
620+
return FALSE;
621621
}

0 commit comments

Comments
 (0)