summaryrefslogtreecommitdiff
path: root/src/corefx
diff options
context:
space:
mode:
authorFilip Navara <filip.navara@gmail.com>2019-02-03 10:26:27 +0100
committerFilip Navara <filip.navara@gmail.com>2019-02-03 11:18:07 +0100
commitc152ba92901a3345a58a42f2a4c5ac5634cfbd3e (patch)
treeabc8e6532e1971b1a2b45f6050dd0ac7b3f2b941 /src/corefx
parent5875f89361938c51cc1943901007aa362e828fae (diff)
downloadcoreclr-c152ba92901a3345a58a42f2a4c5ac5634cfbd3e.tar.gz
coreclr-c152ba92901a3345a58a42f2a4c5ac5634cfbd3e.tar.bz2
coreclr-c152ba92901a3345a58a42f2a4c5ac5634cfbd3e.zip
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
Diffstat (limited to 'src/corefx')
-rw-r--r--src/corefx/System.Globalization.Native/pal_calendarData.c136
-rw-r--r--src/corefx/System.Globalization.Native/pal_collation.c65
-rw-r--r--src/corefx/System.Globalization.Native/pal_icushim.c49
-rw-r--r--src/corefx/System.Globalization.Native/pal_locale.c70
-rw-r--r--src/corefx/System.Globalization.Native/pal_locale.h8
-rw-r--r--src/corefx/System.Globalization.Native/pal_localeNumberData.c66
-rw-r--r--src/corefx/System.Globalization.Native/pal_localeStringData.c104
-rw-r--r--src/corefx/System.Globalization.Native/pal_timeZoneInfo.c9
8 files changed, 249 insertions, 258 deletions
diff --git a/src/corefx/System.Globalization.Native/pal_calendarData.c b/src/corefx/System.Globalization.Native/pal_calendarData.c
index 12b735d1b2..307d0780f8 100644
--- a/src/corefx/System.Globalization.Native/pal_calendarData.c
+++ b/src/corefx/System.Globalization.Native/pal_calendarData.c
@@ -31,7 +31,7 @@ GetCalendarName
Gets the associated ICU calendar name for the CalendarId.
*/
-const char* GetCalendarName(CalendarId calendarId)
+static const char* GetCalendarName(CalendarId calendarId)
{
switch (calendarId)
{
@@ -79,7 +79,7 @@ GetCalendarId
Gets the associated CalendarId for the ICU calendar name.
*/
-CalendarId GetCalendarId(const char* calendarName)
+static CalendarId GetCalendarId(const char* calendarName)
{
if (strcasecmp(calendarName, GREGORIAN_NAME) == 0)
// TODO: what about the other gregorian types?
@@ -115,7 +115,7 @@ int32_t GlobalizationNative_GetCalendars(
{
UErrorCode err = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
- GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
+ GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
UEnumeration* pEnum = ucal_getKeywordValuesForLocale("calendar", locale, TRUE, &err);
int stringEnumeratorCount = uenum_count(pEnum, &err);
int calendarsReturned = 0;
@@ -143,7 +143,9 @@ GetMonthDayPattern
Gets the Month-Day DateTime pattern for the specified locale.
*/
-ResultCode GetMonthDayPattern(const char* locale, UChar* sMonthDay, int32_t stringCapacity)
+static ResultCode GetMonthDayPattern(const char* locale,
+ UChar* sMonthDay,
+ int32_t stringCapacity)
{
UErrorCode err = U_ZERO_ERROR;
UDateTimePatternGenerator* pGenerator = udatpg_open(locale, &err);
@@ -158,7 +160,10 @@ GetNativeCalendarName
Gets the native calendar name.
*/
-ResultCode GetNativeCalendarName(const char* locale, CalendarId calendarId, UChar* nativeName, int32_t stringCapacity)
+static ResultCode GetNativeCalendarName(const char* locale,
+ CalendarId calendarId,
+ UChar* nativeName,
+ int32_t stringCapacity)
{
UErrorCode err = U_ZERO_ERROR;
ULocaleDisplayNames* pDisplayNames = uldn_open(locale, ULDN_STANDARD_NAMES, &err);
@@ -181,7 +186,7 @@ ResultCode GlobalizationNative_GetCalendarInfo(
{
UErrorCode err = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
- GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
+ GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
if (U_FAILURE(err))
return UnknownError;
@@ -193,7 +198,7 @@ ResultCode GlobalizationNative_GetCalendarInfo(
case MonthDay:
return GetMonthDayPattern(locale, result, resultCapacity);
default:
- assert(false);
+ assert(FALSE);
return UnknownError;
}
}
@@ -205,28 +210,28 @@ InvokeCallbackForDatePattern
Gets the ICU date pattern for the specified locale and EStyle and invokes the
callback with the result.
*/
-bool InvokeCallbackForDatePattern(const char* locale,
- UDateFormatStyle style,
- EnumCalendarInfoCallback callback,
- const void* context)
+static int InvokeCallbackForDatePattern(const char* locale,
+ UDateFormatStyle style,
+ EnumCalendarInfoCallback callback,
+ const void* context)
{
UErrorCode err = U_ZERO_ERROR;
UDateFormat* pFormat = udat_open(UDAT_NONE, style, locale, NULL, 0, NULL, 0, &err);
if (U_FAILURE(err))
- return false;
+ return FALSE;
UErrorCode ignore = U_ZERO_ERROR;
- int32_t patternLen = udat_toPattern(pFormat, false, NULL, 0, &ignore) + 1;
+ int32_t patternLen = udat_toPattern(pFormat, FALSE, NULL, 0, &ignore) + 1;
UChar* pattern = calloc(patternLen, sizeof(UChar));
if (pattern == NULL)
{
udat_close(pFormat);
- return false;
+ return FALSE;
}
- udat_toPattern(pFormat, false, pattern, patternLen, &err);
+ udat_toPattern(pFormat, FALSE, pattern, patternLen, &err);
udat_close(pFormat);
if (U_SUCCESS(err))
@@ -235,7 +240,7 @@ bool InvokeCallbackForDatePattern(const char* locale,
}
free(pattern);
- return U_SUCCESS(err);
+ return UErrorCodeToBool(err);
}
/*
@@ -245,16 +250,16 @@ InvokeCallbackForDateTimePattern
Gets the DateTime pattern for the specified skeleton and invokes the callback
with the retrieved value.
*/
-bool InvokeCallbackForDateTimePattern(const char* locale,
- const UChar* patternSkeleton,
- EnumCalendarInfoCallback callback,
- const void* context)
+static int InvokeCallbackForDateTimePattern(const char* locale,
+ const UChar* patternSkeleton,
+ EnumCalendarInfoCallback callback,
+ const void* context)
{
UErrorCode err = U_ZERO_ERROR;
UDateTimePatternGenerator* pGenerator = udatpg_open(locale, &err);
if (U_FAILURE(err))
- return false;
+ return FALSE;
UErrorCode ignore = U_ZERO_ERROR;
int32_t patternLen = udatpg_getBestPattern(pGenerator, patternSkeleton, -1, NULL, 0, &ignore) + 1;
@@ -263,7 +268,7 @@ bool InvokeCallbackForDateTimePattern(const char* locale,
if (bestPattern == NULL)
{
udatpg_close(pGenerator);
- return false;
+ return FALSE;
}
udatpg_getBestPattern(pGenerator, patternSkeleton, -1, bestPattern, patternLen, &err);
@@ -275,7 +280,7 @@ bool InvokeCallbackForDateTimePattern(const char* locale,
}
free(bestPattern);
- return U_SUCCESS(err);
+ return UErrorCodeToBool(err);
}
/*
@@ -285,35 +290,29 @@ EnumSymbols
Enumerates all of the symbols of a type for a locale and calendar and invokes a callback
for each value.
*/
-bool EnumSymbols(const char* locale,
- CalendarId calendarId,
- UDateFormatSymbolType type,
- int32_t startIndex,
- EnumCalendarInfoCallback callback,
- const void* context)
+static int32_t EnumSymbols(const char* locale,
+ CalendarId calendarId,
+ UDateFormatSymbolType type,
+ int32_t startIndex,
+ EnumCalendarInfoCallback callback,
+ const void* context)
{
UErrorCode err = U_ZERO_ERROR;
UDateFormat* pFormat = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, locale, NULL, 0, NULL, 0, &err);
if (U_FAILURE(err))
- return false;
+ return FALSE;
char localeWithCalendarName[ULOC_FULLNAME_CAPACITY];
strncpy(localeWithCalendarName, locale, ULOC_FULLNAME_CAPACITY);
uloc_setKeywordValue("calendar", GetCalendarName(calendarId), localeWithCalendarName, ULOC_FULLNAME_CAPACITY, &err);
- if (U_FAILURE(err))
- {
- udat_close(pFormat);
- return false;
- }
-
UCalendar* pCalendar = ucal_open(NULL, 0, localeWithCalendarName, UCAL_DEFAULT, &err);
if (U_FAILURE(err))
{
udat_close(pFormat);
- return false;
+ return FALSE;
}
udat_setCalendar(pFormat, pCalendar);
@@ -356,10 +355,12 @@ bool EnumSymbols(const char* locale,
udat_close(pFormat);
ucal_close(pCalendar);
- return U_SUCCESS(err);
+ return UErrorCodeToBool(err);
}
-bool EnumUResourceBundle(const UResourceBundle* bundle, EnumCalendarInfoCallback callback, const void* context)
+static void EnumUResourceBundle(const UResourceBundle* bundle,
+ EnumCalendarInfoCallback callback,
+ const void* context)
{
int32_t eraNameCount = ures_getSize(bundle);
@@ -374,15 +375,13 @@ bool EnumUResourceBundle(const UResourceBundle* bundle, EnumCalendarInfoCallback
callback(eraName, context);
}
}
-
- return true;
}
-void CloseResBundle(const UResourceBundle* rootResBundle,
- const UResourceBundle* calResBundle,
- const UResourceBundle* targetCalResBundle,
- const UResourceBundle* erasColResBundle,
- const UResourceBundle* erasResBundle)
+static void CloseResBundle(const UResourceBundle* rootResBundle,
+ const UResourceBundle* calResBundle,
+ const UResourceBundle* targetCalResBundle,
+ const UResourceBundle* erasColResBundle,
+ const UResourceBundle* erasResBundle)
{
ures_close(rootResBundle);
ures_close(calResBundle);
@@ -398,10 +397,10 @@ EnumAbbrevEraNames
Enumerates all the abbreviated era names of the specified locale and calendar, invoking the
callback function for each era name.
*/
-bool EnumAbbrevEraNames(const char* locale,
- CalendarId calendarId,
- EnumCalendarInfoCallback callback,
- const void* context)
+static int32_t EnumAbbrevEraNames(const char* locale,
+ CalendarId calendarId,
+ EnumCalendarInfoCallback callback,
+ const void* context)
{
// The C-API for ICU provides no way to get at the abbreviated era names for a calendar (so we can't use EnumSymbols
// 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,
strncpy(localeNamePtr, locale, ULOC_FULLNAME_CAPACITY);
- while (true)
+ while (TRUE)
{
UErrorCode status = U_ZERO_ERROR;
char* name = GetCalendarName(calendarId);
@@ -429,7 +428,7 @@ bool EnumAbbrevEraNames(const char* locale,
{
EnumUResourceBundle(erasResBundle, callback, context);
CloseResBundle(rootResBundle, calResBundle, targetCalResBundle, erasColResBundle, erasResBundle);
- return true;
+ return TRUE;
}
// 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
the callback for each value in the collection.
The context parameter is passed through to the callback along with each string.
*/
-int32_t GlobalizationNative_EnumCalendarInfo(
- EnumCalendarInfoCallback callback,
- const UChar* localeName,
- CalendarId calendarId,
- CalendarDataType dataType,
- const void* context)
+int32_t GlobalizationNative_EnumCalendarInfo(EnumCalendarInfoCallback callback,
+ const UChar* localeName,
+ CalendarId calendarId,
+ CalendarDataType dataType,
+ const void* context)
{
UErrorCode err = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
- GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
+ GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
if (U_FAILURE(err))
- return false;
+ return FALSE;
switch (dataType)
{
@@ -527,8 +525,8 @@ int32_t GlobalizationNative_EnumCalendarInfo(
case AbbrevEraNames:
return EnumAbbrevEraNames(locale, calendarId, callback, context);
default:
- assert(false);
- return false;
+ assert(FALSE);
+ return FALSE;
}
}
@@ -559,8 +557,10 @@ GetJapaneseEraInfo
Gets the starting Gregorian date of the specified Japanese Era.
*/
-int32_t GlobalizationNative_GetJapaneseEraStartDate(
- int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay)
+int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era,
+ int32_t* startYear,
+ int32_t* startMonth,
+ int32_t* startDay)
{
*startYear = -1;
*startMonth = -1;
@@ -570,7 +570,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(
UCalendar* pCal = ucal_open(NULL, 0, JAPANESE_LOCALE_AND_CALENDAR, UCAL_TRADITIONAL, &err);
if (U_FAILURE(err))
- return false;
+ return FALSE;
ucal_set(pCal, UCAL_ERA, era);
ucal_set(pCal, UCAL_YEAR, 1);
@@ -580,7 +580,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(
if (U_FAILURE(err))
{
ucal_close(pCal);
- return false;
+ return FALSE;
}
// set the date to Jan 1
@@ -607,7 +607,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(
*startDay = ucal_get(pCal, UCAL_DATE, &err);
ucal_close(pCal);
- return U_SUCCESS(err);
+ return UErrorCodeToBool(err);
}
}
}
@@ -617,5 +617,5 @@ int32_t GlobalizationNative_GetJapaneseEraStartDate(
}
ucal_close(pCal);
- return false;
+ return FALSE;
}
diff --git a/src/corefx/System.Globalization.Native/pal_collation.c b/src/corefx/System.Globalization.Native/pal_collation.c
index 74f7bb3068..a56aa09cc5 100644
--- a/src/corefx/System.Globalization.Native/pal_collation.c
+++ b/src/corefx/System.Globalization.Native/pal_collation.c
@@ -6,7 +6,6 @@
#include <assert.h>
#include <pthread.h>
#include <stdlib.h>
-#include <stdbool.h>
#include <stdint.h>
#include <search.h>
#include <string.h>
@@ -100,7 +99,7 @@ Thus, to use these characters in a rule, they need to be escaped.
This rule was taken from http://www.unicode.org/reports/tr35/tr35-collation.html#Rules.
*/
-bool NeedsEscape(UChar character)
+static int NeedsEscape(UChar character)
{
return ((0x21 <= character && character <= 0x2f)
|| (0x3a <= character && character <= 0x40)
@@ -118,13 +117,13 @@ This is done so we can use range checks instead of comparing individual characte
These ranges were obtained by running the above characters through .NET CompareInfo.Compare
with CompareOptions.IgnoreSymbols on Windows.
*/
-bool IsHalfFullHigherSymbol(UChar character)
+static int IsHalfFullHigherSymbol(UChar character)
{
return (0xffe0 <= character && character <= 0xffe6)
|| (0xff61 <= character && character <= 0xff65);
}
-static bool AddItem(UCharList* list, const UChar item)
+static int AddItem(UCharList* list, const UChar item)
{
size_t size = list->size++;
if (size >= list->capacity)
@@ -133,13 +132,13 @@ static bool AddItem(UCharList* list, const UChar item)
UChar* ptr = (UChar*)realloc(list->items, list->capacity * sizeof(UChar*));
if (ptr == NULL)
{
- return false;
+ return FALSE;
}
list->items = ptr;
}
list->items[size] = item;
- return true;
+ return TRUE;
}
/*
@@ -148,18 +147,18 @@ Gets a string of custom collation rules, if necessary.
Since the CompareOptions flags don't map 1:1 with ICU default functionality, we need to fall back to using
custom rules in order to support IgnoreKanaType and IgnoreWidth CompareOptions correctly.
*/
-UCharList* GetCustomRules(int32_t options, UColAttributeValue strength, bool isIgnoreSymbols)
+static UCharList* GetCustomRules(int32_t options, UColAttributeValue strength, int isIgnoreSymbols)
{
- bool isIgnoreKanaType = (options & CompareOptionsIgnoreKanaType) == CompareOptionsIgnoreKanaType;
- bool isIgnoreWidth = (options & CompareOptionsIgnoreWidth) == CompareOptionsIgnoreWidth;
+ int isIgnoreKanaType = (options & CompareOptionsIgnoreKanaType) == CompareOptionsIgnoreKanaType;
+ int isIgnoreWidth = (options & CompareOptionsIgnoreWidth) == CompareOptionsIgnoreWidth;
// kana differs at the tertiary level
- bool needsIgnoreKanaTypeCustomRule = isIgnoreKanaType && strength >= UCOL_TERTIARY;
- bool needsNotIgnoreKanaTypeCustomRule = !isIgnoreKanaType && strength < UCOL_TERTIARY;
+ int needsIgnoreKanaTypeCustomRule = isIgnoreKanaType && strength >= UCOL_TERTIARY;
+ int needsNotIgnoreKanaTypeCustomRule = !isIgnoreKanaType && strength < UCOL_TERTIARY;
// character width differs at the tertiary level
- bool needsIgnoreWidthCustomRule = isIgnoreWidth && strength >= UCOL_TERTIARY;
- bool needsNotIgnoreWidthCustomRule = !isIgnoreWidth && strength < UCOL_TERTIARY;
+ int needsIgnoreWidthCustomRule = isIgnoreWidth && strength >= UCOL_TERTIARY;
+ int needsNotIgnoreWidthCustomRule = !isIgnoreWidth && strength < UCOL_TERTIARY;
if (!(needsIgnoreKanaTypeCustomRule || needsNotIgnoreKanaTypeCustomRule || needsIgnoreWidthCustomRule || needsNotIgnoreWidthCustomRule))
return NULL;
@@ -212,7 +211,7 @@ UCharList* GetCustomRules(int32_t options, UColAttributeValue strength, bool isI
UChar lowerChar;
UChar higherChar;
- bool needsEscape;
+ int needsEscape;
for (int i = 0; i < g_HalfFullCharsLength; i++)
{
lowerChar = g_HalfFullLowerChars[i];
@@ -251,9 +250,9 @@ UCollator* CloneCollatorWithOptions(const UCollator* pCollator, int32_t options,
{
UColAttributeValue strength = ucol_getStrength(pCollator);
- bool isIgnoreCase = (options & CompareOptionsIgnoreCase) == CompareOptionsIgnoreCase;
- bool isIgnoreNonSpace = (options & CompareOptionsIgnoreNonSpace) == CompareOptionsIgnoreNonSpace;
- bool isIgnoreSymbols = (options & CompareOptionsIgnoreSymbols) == CompareOptionsIgnoreSymbols;
+ int isIgnoreCase = (options & CompareOptionsIgnoreCase) == CompareOptionsIgnoreCase;
+ int isIgnoreNonSpace = (options & CompareOptionsIgnoreNonSpace) == CompareOptionsIgnoreNonSpace;
+ int isIgnoreSymbols = (options & CompareOptionsIgnoreSymbols) == CompareOptionsIgnoreSymbols;
if (isIgnoreCase)
{
@@ -325,36 +324,28 @@ UCollator* CloneCollatorWithOptions(const UCollator* pCollator, int32_t options,
}
// Returns TRUE if all the collation elements in str are completely ignorable
-bool CanIgnoreAllCollationElements(const UCollator* pColl, const UChar* lpStr, int32_t length)
+static int CanIgnoreAllCollationElements(const UCollator* pColl, const UChar* lpStr, int32_t length)
{
- bool result = false;
+ int result = TRUE;
UErrorCode err = U_ZERO_ERROR;
UCollationElements* pCollElem = ucol_openElements(pColl, lpStr, length, &err);
if (U_SUCCESS(err))
{
int32_t curCollElem = UCOL_NULLORDER;
-
- result = true;
-
while ((curCollElem = ucol_next(pCollElem, &err)) != UCOL_NULLORDER)
{
if (curCollElem != 0)
{
- result = false;
+ result = FALSE;
break;
}
}
- if (U_FAILURE(err))
- {
- result = false;
- }
-
ucol_closeElements(pCollElem);
}
- return result;
+ return U_SUCCESS(err) ? result : FALSE;
}
@@ -371,7 +362,7 @@ void CreateSortHandle(SortHandle** ppSortHandle)
if (result != 0)
{
- assert(false && "Unexpected pthread_mutex_init return value.");
+ assert(FALSE && "Unexpected pthread_mutex_init return value.");
}
}
@@ -429,7 +420,7 @@ const UCollator* GetCollatorFromSortHandle(SortHandle* pSortHandle, int32_t opti
int lockResult = pthread_mutex_lock(&pSortHandle->collatorsLockObject);
if (lockResult != 0)
{
- assert(false && "Unexpected pthread_mutex_lock return value.");
+ assert(FALSE && "Unexpected pthread_mutex_lock return value.");
}
TCollatorMap* map = (TCollatorMap*)malloc(sizeof(TCollatorMap));
@@ -465,7 +456,7 @@ int32_t GlobalizationNative_GetSortVersion(SortHandle* pSortHandle)
}
else
{
- assert(false && "Unexpected ucol_getVersion to fail.");
+ assert(FALSE && "Unexpected ucol_getVersion to fail.");
// we didn't use UCOL_TAILORINGS_VERSION because it is deprecated in ICU v5
result = UCOL_RUNTIME_VERSION << 16 | UCOL_BUILDER_VERSION;
@@ -564,13 +555,13 @@ int32_t GlobalizationNative_LastIndexOf(
Static Function:
AreEqualOrdinalIgnoreCase
*/
-static bool AreEqualOrdinalIgnoreCase(UChar32 one, UChar32 two)
+static int AreEqualOrdinalIgnoreCase(UChar32 one, UChar32 two)
{
// Return whether the two characters are identical or would be identical if they were upper-cased.
if (one == two)
{
- return true;
+ return TRUE;
}
if (one == 0x0131 || two == 0x0131)
@@ -578,7 +569,7 @@ static bool AreEqualOrdinalIgnoreCase(UChar32 one, UChar32 two)
// On Windows with InvariantCulture, the LATIN SMALL LETTER DOTLESS I (U+0131)
// capitalizes to itself, whereas with ICU it capitalizes to LATIN CAPITAL LETTER I (U+0049).
// We special case it to match the Windows invariant behavior.
- return false;
+ return FALSE;
}
return u_toupper(one) == u_toupper(two);
@@ -603,14 +594,14 @@ int32_t GlobalizationNative_IndexOfOrdinalIgnoreCase(
const UChar *src = lpSource, *trg = lpTarget;
UChar32 srcCodepoint, trgCodepoint;
- bool match = true;
+ int32_t match = TRUE;
while (trgIdx < cwTargetLength)
{
U16_NEXT(src, srcIdx, cwSourceLength, srcCodepoint);
U16_NEXT(trg, trgIdx, cwTargetLength, trgCodepoint);
if (!AreEqualOrdinalIgnoreCase(srcCodepoint, trgCodepoint))
{
- match = false;
+ match = FALSE;
break;
}
}
diff --git a/src/corefx/System.Globalization.Native/pal_icushim.c b/src/corefx/System.Globalization.Native/pal_icushim.c
index df92dec8b6..ce42af642f 100644
--- a/src/corefx/System.Globalization.Native/pal_icushim.c
+++ b/src/corefx/System.Globalization.Native/pal_icushim.c
@@ -5,7 +5,6 @@
#include <dlfcn.h>
#include <stdlib.h>
-#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
@@ -28,7 +27,7 @@ static void* libicui18n = NULL;
#ifdef __APPLE__
-bool FindICULibs(const char* versionPrefix, char* symbolName, char* symbolVersion)
+static int FindICULibs(const char* versionPrefix, char* symbolName, char* symbolVersion)
{
#ifndef OSX_ICU_LIBRARY_PATH
c_static_assert_msg(false, "The ICU Library path is not defined");
@@ -39,13 +38,13 @@ bool FindICULibs(const char* versionPrefix, char* symbolName, char* symbolVersio
if (libicuuc == NULL)
{
- return false;
+ return FALSE;
}
// in OSX all ICU APIs exist in the same library libicucore.A.dylib
libicui18n = libicuuc;
- return true;
+ return TRUE;
}
#else // __APPLE__
@@ -67,7 +66,7 @@ static const int MaxSubICUVersion = 5;
// 1. Only majorVer is not equal to -1 => result is baseFileName.majorver
// 2. Only majorVer and minorVer are not equal to -1 => result is baseFileName.majorver.minorVer
// 3. All components are not equal to -1 => result is baseFileName.majorver.minorVer.subver
-void GetVersionedLibFileName(const char* baseFileName, int majorVer, int minorVer, int subVer, const char* versionPrefix, char* result)
+static void GetVersionedLibFileName(const char* baseFileName, int majorVer, int minorVer, int subVer, const char* versionPrefix, char* result)
{
assert(majorVer != -1);
@@ -83,7 +82,7 @@ void GetVersionedLibFileName(const char* baseFileName, int majorVer, int minorVe
}
}
-bool FindSymbolVersion(int majorVer, int minorVer, int subVer, char* symbolName, char* symbolVersion)
+static int FindSymbolVersion(int majorVer, int minorVer, int subVer, char* symbolName, char* symbolVersion)
{
// Find out the format of the version string added to each symbol
// First try just the unversioned symbol
@@ -104,17 +103,17 @@ bool FindSymbolVersion(int majorVer, int minorVer, int subVer, char* symbolName,
sprintf(symbolName, "u_strlen%s", symbolVersion);
if (dlsym(libicuuc, symbolName) == NULL)
{
- return false;
+ return FALSE;
}
}
}
}
- return true;
+ return TRUE;
}
// Try to open the necessary ICU libraries
-bool OpenICULibraries(int majorVer, int minorVer, int subVer, const char* versionPrefix, char* symbolName, char* symbolVersion)
+static int OpenICULibraries(int majorVer, int minorVer, int subVer, const char* versionPrefix, char* symbolName, char* symbolVersion)
{
char libicuucName[64];
char libicui18nName[64];
@@ -146,7 +145,7 @@ bool OpenICULibraries(int majorVer, int minorVer, int subVer, const char* versio
// environment variable.
// The format of the string in this variable is majorVer[.minorVer[.subVer]] (the brackets
// indicate optional parts).
-bool FindLibUsingOverride(const char* versionPrefix, char* symbolName, char* symbolVersion)
+static int FindLibUsingOverride(const char* versionPrefix, char* symbolName, char* symbolVersion)
{
char* versionOverride = getenv("CLR_ICU_VERSION_OVERRIDE");
if (versionOverride != NULL)
@@ -160,16 +159,16 @@ bool FindLibUsingOverride(const char* versionPrefix, char* symbolName, char* sym
{
if (OpenICULibraries(first, second, third, versionPrefix, symbolName, symbolVersion))
{
- return true;
+ return TRUE;
}
}
}
- return false;
+ return FALSE;
}
// Search for library files with names including the major version.
-bool FindLibWithMajorVersion(const char* versionPrefix, char* symbolName, char* symbolVersion)
+static int FindLibWithMajorVersion(const char* versionPrefix, char* symbolName, char* symbolVersion)
{
// ICU packaging documentation (http://userguide.icu-project.org/packaging)
// describes applications link against the major (e.g. libicuuc.so.54).
@@ -177,7 +176,7 @@ bool FindLibWithMajorVersion(const char* versionPrefix, char* symbolName, char*
// Select the version of ICU present at build time.
if (OpenICULibraries(MinICUVersion, -1, -1, versionPrefix, symbolName, symbolVersion))
{
- return true;
+ return TRUE;
}
// Select the highest supported version of ICU present on the local machine
@@ -185,16 +184,16 @@ bool FindLibWithMajorVersion(const char* versionPrefix, char* symbolName, char*
{
if (OpenICULibraries(i, -1, -1, versionPrefix, symbolName, symbolVersion))
{
- return true;
+ return TRUE;
}
}
- return false;
+ return FALSE;
}
// Select the highest supported version of ICU present on the local machine
// Search for library files with names including the major and minor version.
-bool FindLibWithMajorMinorVersion(const char* versionPrefix, char* symbolName, char* symbolVersion)
+static int FindLibWithMajorMinorVersion(const char* versionPrefix, char* symbolName, char* symbolVersion)
{
for (int i = MaxICUVersion; i >= MinICUVersion; i--)
{
@@ -202,17 +201,17 @@ bool FindLibWithMajorMinorVersion(const char* versionPrefix, char* symbolName, c
{
if (OpenICULibraries(i, j, -1, versionPrefix, symbolName, symbolVersion))
{
- return true;
+ return TRUE;
}
}
}
- return false;
+ return FALSE;
}
// Select the highest supported version of ICU present on the local machine
// Search for library files with names including the major, minor and sub version.
-bool FindLibWithMajorMinorSubVersion(const char* versionPrefix, char* symbolName, char* symbolVersion)
+static int FindLibWithMajorMinorSubVersion(const char* versionPrefix, char* symbolName, char* symbolVersion)
{
for (int i = MaxICUVersion; i >= MinICUVersion; i--)
{
@@ -222,17 +221,17 @@ bool FindLibWithMajorMinorSubVersion(const char* versionPrefix, char* symbolName
{
if (OpenICULibraries(i, j, k, versionPrefix, symbolName, symbolVersion))
{
- return true;
+ return TRUE;
}
}
}
}
- return false;
+ return FALSE;
}
-bool FindICULibs(const char* versionPrefix, char* symbolName, char* symbolVersion)
+static int FindICULibs(const char* versionPrefix, char* symbolName, char* symbolVersion)
{
return FindLibUsingOverride(versionPrefix, symbolName, symbolVersion) ||
FindLibWithMajorVersion(versionPrefix, symbolName, symbolVersion) ||
@@ -257,7 +256,7 @@ int32_t GlobalizationNative_LoadICU()
if (!FindICULibs(VERSION_PREFIX_SUSE, symbolName, symbolVersion))
#endif
{
- return 0;
+ return FALSE;
}
}
@@ -276,7 +275,7 @@ int32_t GlobalizationNative_LoadICU()
libicui18n = NULL;
#endif // __APPLE__
- return 1;
+ return TRUE;
}
// GlobalizationNative_GetICUVersion
diff --git a/src/corefx/System.Globalization.Native/pal_locale.c b/src/corefx/System.Globalization.Native/pal_locale.c
index 6b9561122c..b7465df276 100644
--- a/src/corefx/System.Globalization.Native/pal_locale.c
+++ b/src/corefx/System.Globalization.Native/pal_locale.c
@@ -15,7 +15,7 @@ int32_t UErrorCodeToBool(UErrorCode status)
{
if (U_SUCCESS(status))
{
- return 1;
+ return TRUE;
}
// assert errors that should never occur
@@ -24,15 +24,23 @@ int32_t UErrorCodeToBool(UErrorCode status)
// add possible SetLastError support here
- return 0;
+ return FALSE;
}
-int32_t GetLocale(
- const UChar* localeName, char* localeNameResult, int32_t localeNameResultLength, bool canonicalize, UErrorCode* err)
+int32_t GetLocale(const UChar* localeName,
+ char* localeNameResult,
+ int32_t localeNameResultLength,
+ UBool canonicalize,
+ UErrorCode* err)
{
char localeNameTemp[ULOC_FULLNAME_CAPACITY] = {0};
int32_t localeLength;
+ if (U_FAILURE(*err))
+ {
+ return 0;
+ }
+
// Convert ourselves instead of doing u_UCharsToChars as that function considers '@' a variant and stops.
for (int i = 0; i < ULOC_FULLNAME_CAPACITY - 1; i++)
{
@@ -81,17 +89,21 @@ int32_t GetLocale(
return localeLength;
}
-UErrorCode u_charsToUChars_safe(const char* str, UChar* value, int32_t valueLength)
+void u_charsToUChars_safe(const char* str, UChar* value, int32_t valueLength, UErrorCode* err)
{
- int len = strlen(str);
+ if (U_FAILURE(*err))
+ {
+ return;
+ }
+ int len = strlen(str);
if (len >= valueLength)
{
- return U_BUFFER_OVERFLOW_ERROR;
+ *err = U_BUFFER_OVERFLOW_ERROR;
+ return;
}
u_charsToUChars(str, value, len + 1);
- return U_ZERO_ERROR;
}
int32_t FixupLocaleName(UChar* value, int32_t valueLength)
@@ -112,7 +124,7 @@ int32_t FixupLocaleName(UChar* value, int32_t valueLength)
return i;
}
-bool IsEnvVarSet(const char* name)
+static int IsEnvVarSet(const char* name)
{
const char* value = getenv(name);
@@ -202,16 +214,12 @@ int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value,
UErrorCode status = U_ZERO_ERROR;
char localeNameBuffer[ULOC_FULLNAME_CAPACITY];
- GetLocale(localeName, localeNameBuffer, ULOC_FULLNAME_CAPACITY, true, &status);
+ GetLocale(localeName, localeNameBuffer, ULOC_FULLNAME_CAPACITY, TRUE, &status);
+ u_charsToUChars_safe(localeNameBuffer, value, valueLength, &status);
if (U_SUCCESS(status))
{
- status = u_charsToUChars_safe(localeNameBuffer, value, valueLength);
-
- if (U_SUCCESS(status))
- {
- FixupLocaleName(value, valueLength);
- }
+ FixupLocaleName(value, valueLength);
}
return UErrorCodeToBool(status);
@@ -225,30 +233,22 @@ int32_t GlobalizationNative_GetDefaultLocaleName(UChar* value, int32_t valueLeng
const char* defaultLocale = DetectDefaultLocaleName();
uloc_getBaseName(defaultLocale, localeNameBuffer, ULOC_FULLNAME_CAPACITY, &status);
+ u_charsToUChars_safe(localeNameBuffer, value, valueLength, &status);
if (U_SUCCESS(status))
{
- status = u_charsToUChars_safe(localeNameBuffer, value, valueLength);
-
- if (U_SUCCESS(status))
- {
- int localeNameLen = FixupLocaleName(value, valueLength);
+ int localeNameLen = FixupLocaleName(value, valueLength);
- char collationValueTemp[ULOC_KEYWORDS_CAPACITY];
- int32_t collationLen =
- uloc_getKeywordValue(defaultLocale, "collation", collationValueTemp, ULOC_KEYWORDS_CAPACITY, &status);
+ char collationValueTemp[ULOC_KEYWORDS_CAPACITY];
+ int32_t collationLen =
+ uloc_getKeywordValue(defaultLocale, "collation", collationValueTemp, ULOC_KEYWORDS_CAPACITY, &status);
- if (U_SUCCESS(status) && collationLen > 0)
- {
- // copy the collation; managed uses a "_" to represent collation (not
- // "@collation=")
- status = u_charsToUChars_safe("_", &value[localeNameLen], valueLength - localeNameLen);
- if (U_SUCCESS(status))
- {
- status = u_charsToUChars_safe(
- collationValueTemp, &value[localeNameLen + 1], valueLength - localeNameLen - 1);
- }
- }
+ if (U_SUCCESS(status) && collationLen > 0)
+ {
+ // copy the collation; managed uses a "_" to represent collation (not
+ // "@collation=")
+ u_charsToUChars_safe("_", &value[localeNameLen], valueLength - localeNameLen, &status);
+ u_charsToUChars_safe(collationValueTemp, &value[localeNameLen + 1], valueLength - localeNameLen - 1, &status);
}
}
diff --git a/src/corefx/System.Globalization.Native/pal_locale.h b/src/corefx/System.Globalization.Native/pal_locale.h
index ebd64468be..134291e4d4 100644
--- a/src/corefx/System.Globalization.Native/pal_locale.h
+++ b/src/corefx/System.Globalization.Native/pal_locale.h
@@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-#include <stdbool.h>
-
#include "pal_icushim.h"
/*
@@ -24,7 +22,7 @@ Converts a managed localeName into something ICU understands and can use as a lo
int32_t GetLocale(const UChar* localeName,
char* localeNameResult,
int32_t localeNameResultLength,
- bool canonicalize,
+ UBool canonicalize,
UErrorCode* err);
/*
@@ -33,7 +31,7 @@ u_charsToUChars_safe
Copies the given null terminated char* to UChar with error checking. Replacement for ICU u_charsToUChars
*/
-UErrorCode u_charsToUChars_safe(const char* str, UChar* value, int32_t valueLength);
+void u_charsToUChars_safe(const char* str, UChar* value, int32_t valueLength, UErrorCode* err);
/*
Function:
@@ -42,7 +40,7 @@ FixupLocaleName
Replace underscores with hyphens to interop with existing .NET code.
Returns the length of the string.
*/
-int FixupLocaleName(UChar* value, int32_t valueLength);
+int32_t FixupLocaleName(UChar* value, int32_t valueLength);
/*
Function:
diff --git a/src/corefx/System.Globalization.Native/pal_localeNumberData.c b/src/corefx/System.Globalization.Native/pal_localeNumberData.c
index 1a13b92f6b..84af3ba496 100644
--- a/src/corefx/System.Globalization.Native/pal_localeNumberData.c
+++ b/src/corefx/System.Globalization.Native/pal_localeNumberData.c
@@ -5,7 +5,6 @@
#include <assert.h>
#include <stdlib.h>
-#include <stdbool.h>
#include <string.h>
#include "pal_localeNumberData.h"
@@ -30,7 +29,7 @@ NormalizeNumericPattern
Returns a numeric string pattern in a format that we can match against the
appropriate managed pattern.
*/
-char* NormalizeNumericPattern(const UChar* srcPattern, bool isNegative)
+static char* NormalizeNumericPattern(const UChar* srcPattern, int isNegative)
{
int iStart = 0;
int iEnd = u_strlen(srcPattern);
@@ -57,10 +56,10 @@ char* NormalizeNumericPattern(const UChar* srcPattern, bool isNegative)
}
int index = 0;
- bool minusAdded = false;
- bool digitAdded = false;
- bool currencyAdded = false;
- bool spaceAdded = false;
+ int minusAdded = FALSE;
+ int digitAdded = FALSE;
+ int currencyAdded = FALSE;
+ int spaceAdded = FALSE;
for (int i = iStart; i <= iEnd; i++)
{
@@ -70,7 +69,7 @@ char* NormalizeNumericPattern(const UChar* srcPattern, bool isNegative)
case UCHAR_MINUS:
case UCHAR_OPENPAREN:
case UCHAR_CLOSEPAREN:
- minusAdded = true;
+ minusAdded = TRUE;
break;
}
}
@@ -104,7 +103,7 @@ char* NormalizeNumericPattern(const UChar* srcPattern, bool isNegative)
case UCHAR_DIGIT:
if (!digitAdded)
{
- digitAdded = true;
+ digitAdded = TRUE;
destPattern[index++] = 'n';
}
break;
@@ -112,7 +111,7 @@ char* NormalizeNumericPattern(const UChar* srcPattern, bool isNegative)
case UCHAR_CURRENCY:
if (!currencyAdded)
{
- currencyAdded = true;
+ currencyAdded = TRUE;
destPattern[index++] = 'C';
}
break;
@@ -121,19 +120,19 @@ char* NormalizeNumericPattern(const UChar* srcPattern, bool isNegative)
case UCHAR_NBSPACE:
if (!spaceAdded)
{
- spaceAdded = true;
+ spaceAdded = TRUE;
destPattern[index++] = ' ';
}
else
{
- assert(false);
+ assert(FALSE);
}
break;
case UCHAR_MINUS:
case UCHAR_OPENPAREN:
case UCHAR_CLOSEPAREN:
- minusAdded = true;
+ minusAdded = TRUE;
destPattern[index++] = (char)ch;
break;
@@ -154,13 +153,16 @@ Determines the pattern from the decimalFormat and returns the matching pattern's
index from patterns[].
Returns index -1 if no pattern is found.
*/
-int GetNumericPattern(const UNumberFormat* pNumberFormat, const char* patterns[], int patternsCount, bool isNegative)
+static int GetNumericPattern(const UNumberFormat* pNumberFormat,
+ const char* patterns[],
+ int patternsCount,
+ int isNegative)
{
const int INVALID_FORMAT = -1;
const int MAX_DOTNET_NUMERIC_PATTERN_LENGTH = 6; // example: "(C n)" plus terminator
UErrorCode ignore = U_ZERO_ERROR;
- int32_t icuPatternLength = unum_toPattern(pNumberFormat, false, NULL, 0, &ignore) + 1;
+ int32_t icuPatternLength = unum_toPattern(pNumberFormat, FALSE, NULL, 0, &ignore) + 1;
UChar* icuPattern = calloc(icuPatternLength, sizeof(UChar));
if (icuPattern == NULL)
@@ -170,7 +172,7 @@ int GetNumericPattern(const UNumberFormat* pNumberFormat, const char* patterns[]
UErrorCode err = U_ZERO_ERROR;
- unum_toPattern(pNumberFormat, false, icuPattern, icuPatternLength, &err);
+ unum_toPattern(pNumberFormat, FALSE, icuPattern, icuPatternLength, &err);
assert(U_SUCCESS(err));
@@ -196,9 +198,9 @@ int GetNumericPattern(const UNumberFormat* pNumberFormat, const char* patterns[]
free(normalizedPattern);
return i;
}
- };
+ }
- assert(false); // should have found a valid pattern
+ assert(FALSE); // should have found a valid pattern
free(normalizedPattern);
return INVALID_FORMAT;
}
@@ -210,7 +212,7 @@ GetCurrencyNegativePattern
Implementation of NumberFormatInfo.CurrencyNegativePattern.
Returns the pattern index.
*/
-int GetCurrencyNegativePattern(const char* locale)
+static int GetCurrencyNegativePattern(const char* locale)
{
const int DEFAULT_VALUE = 0;
static const char* Patterns[] = {"(Cn)",
@@ -237,7 +239,7 @@ int GetCurrencyNegativePattern(const char* locale)
if (U_SUCCESS(status))
{
- int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), true);
+ int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), TRUE);
if (value >= 0)
{
unum_close(pFormat);
@@ -256,7 +258,7 @@ GetCurrencyPositivePattern
Implementation of NumberFormatInfo.CurrencyPositivePattern.
Returns the pattern index.
*/
-int GetCurrencyPositivePattern(const char* locale)
+static int GetCurrencyPositivePattern(const char* locale)
{
const int DEFAULT_VALUE = 0;
static const char* Patterns[] = {"Cn", "nC", "C n", "n C"};
@@ -268,7 +270,7 @@ int GetCurrencyPositivePattern(const char* locale)
if (U_SUCCESS(status))
{
- int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), false);
+ int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), FALSE);
if (value >= 0)
{
unum_close(pFormat);
@@ -287,7 +289,7 @@ GetNumberNegativePattern
Implementation of NumberFormatInfo.NumberNegativePattern.
Returns the pattern index.
*/
-int GetNumberNegativePattern(const char* locale)
+static int GetNumberNegativePattern(const char* locale)
{
const int DEFAULT_VALUE = 1;
static const char* Patterns[] = {"(n)", "-n", "- n", "n-", "n -"};
@@ -299,7 +301,7 @@ int GetNumberNegativePattern(const char* locale)
if (U_SUCCESS(status))
{
- int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), true);
+ int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), TRUE);
if (value >= 0)
{
unum_close(pFormat);
@@ -318,7 +320,7 @@ GetPercentNegativePattern
Implementation of NumberFormatInfo.PercentNegativePattern.
Returns the pattern index.
*/
-int GetPercentNegativePattern(const char* locale)
+static int GetPercentNegativePattern(const char* locale)
{
const int DEFAULT_VALUE = 0;
static const char* Patterns[] = {
@@ -331,7 +333,7 @@ int GetPercentNegativePattern(const char* locale)
if (U_SUCCESS(status))
{
- int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), true);
+ int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), TRUE);
if (value >= 0)
{
unum_close(pFormat);
@@ -350,7 +352,7 @@ GetPercentPositivePattern
Implementation of NumberFormatInfo.PercentPositivePattern.
Returns the pattern index.
*/
-int GetPercentPositivePattern(const char* locale)
+static int GetPercentPositivePattern(const char* locale)
{
const int DEFAULT_VALUE = 0;
static const char* Patterns[] = {"n %", "n%", "%n", "% n"};
@@ -362,7 +364,7 @@ int GetPercentPositivePattern(const char* locale)
if (U_SUCCESS(status))
{
- int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), false);
+ int value = GetNumericPattern(pFormat, Patterns, ARRAY_LENGTH(Patterns), FALSE);
if (value >= 0)
{
unum_close(pFormat);
@@ -381,7 +383,7 @@ GetMeasurementSystem
Obtains the measurement system for the local, determining if US or metric.
Returns 1 for US, 0 otherwise.
*/
-UErrorCode GetMeasurementSystem(const char* locale, int32_t* value)
+static UErrorCode GetMeasurementSystem(const char* locale, int32_t* value)
{
UErrorCode status = U_ZERO_ERROR;
@@ -406,11 +408,11 @@ int32_t GlobalizationNative_GetLocaleInfoInt(
{
UErrorCode status = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
- GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &status);
+ GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &status);
if (U_FAILURE(status))
{
- return UErrorCodeToBool(U_ILLEGAL_ARGUMENT_ERROR);
+ return FALSE;
}
switch (localeNumberData)
@@ -513,7 +515,7 @@ int32_t GlobalizationNative_GetLocaleInfoInt(
break;
default:
status = U_UNSUPPORTED_ERROR;
- assert(false);
+ assert(FALSE);
break;
}
@@ -532,7 +534,7 @@ int32_t GlobalizationNative_GetLocaleInfoGroupingSizes(
{
UErrorCode status = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
- GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &status);
+ GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &status);
if (U_FAILURE(status))
{
diff --git a/src/corefx/System.Globalization.Native/pal_localeStringData.c b/src/corefx/System.Globalization.Native/pal_localeStringData.c
index f8c9e87937..97cc42acac 100644
--- a/src/corefx/System.Globalization.Native/pal_localeStringData.c
+++ b/src/corefx/System.Globalization.Native/pal_localeStringData.c
@@ -15,8 +15,10 @@ GetLocaleInfoDecimalFormatSymbol
Obtains the value of a DecimalFormatSymbols
*/
-UErrorCode
-GetLocaleInfoDecimalFormatSymbol(const char* locale, UNumberFormatSymbol symbol, UChar* value, int32_t valueLength)
+static UErrorCode GetLocaleInfoDecimalFormatSymbol(const char* locale,
+ UNumberFormatSymbol symbol,
+ UChar* value,
+ int32_t valueLength)
{
UErrorCode status = U_ZERO_ERROR;
UNumberFormat* pFormat = unum_open(UNUM_DECIMAL, NULL, 0, locale, NULL, &status);
@@ -31,12 +33,12 @@ GetDigitSymbol
Obtains the value of a Digit DecimalFormatSymbols
*/
-UErrorCode GetDigitSymbol(const char* locale,
- UErrorCode previousStatus,
- UNumberFormatSymbol symbol,
- int digit,
- UChar* value,
- int32_t valueLength)
+static UErrorCode GetDigitSymbol(const char* locale,
+ UErrorCode previousStatus,
+ UNumberFormatSymbol symbol,
+ int digit,
+ UChar* value,
+ int32_t valueLength)
{
if (U_FAILURE(previousStatus))
{
@@ -52,7 +54,10 @@ GetLocaleInfoAmPm
Obtains the value of the AM or PM string for a locale.
*/
-UErrorCode GetLocaleInfoAmPm(const char* locale, bool am, UChar* value, int32_t valueLength)
+static UErrorCode GetLocaleInfoAmPm(const char* locale,
+ int am,
+ UChar* value,
+ int32_t valueLength)
{
UErrorCode status = U_ZERO_ERROR;
UDateFormat* pFormat = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, locale, NULL, 0, NULL, 0, &status);
@@ -67,27 +72,21 @@ GetLocaleIso639LanguageTwoLetterName
Gets the language name for a locale (via uloc_getLanguage) and converts the result to UChars
*/
-UErrorCode GetLocaleIso639LanguageTwoLetterName(const char* locale, UChar* value, int32_t valueLength)
+static UErrorCode GetLocaleIso639LanguageTwoLetterName(const char* locale, UChar* value, int32_t valueLength)
{
- UErrorCode status = U_ZERO_ERROR;
- int32_t length = uloc_getLanguage(locale, NULL, 0, &status) + 1;
+ UErrorCode status = U_ZERO_ERROR, ignore = U_ZERO_ERROR;
+ int32_t length = uloc_getLanguage(locale, NULL, 0, &ignore) + 1;
- assert(status == U_BUFFER_OVERFLOW_ERROR);
char* buf = calloc(length, sizeof(char));
if (buf == NULL)
{
return U_MEMORY_ALLOCATION_ERROR;
}
- status = U_ZERO_ERROR;
uloc_getLanguage(locale, buf, length, &status);
-
- if (U_SUCCESS(status))
- {
- status = u_charsToUChars_safe(buf, value, valueLength);
- }
-
+ u_charsToUChars_safe(buf, value, valueLength, &status);
free(buf);
+
return status;
}
@@ -97,15 +96,17 @@ GetLocaleIso639LanguageThreeLetterName
Gets the language name for a locale (via uloc_getISO3Language) and converts the result to UChars
*/
-UErrorCode GetLocaleIso639LanguageThreeLetterName(const char* locale, UChar* value, int32_t valueLength)
+static UErrorCode GetLocaleIso639LanguageThreeLetterName(const char* locale, UChar* value, int32_t valueLength)
{
+ UErrorCode status = U_ZERO_ERROR;
const char *isoLanguage = uloc_getISO3Language(locale);
if (isoLanguage[0] == 0)
{
return U_ILLEGAL_ARGUMENT_ERROR;
}
- return u_charsToUChars_safe(isoLanguage, value, valueLength);
+ u_charsToUChars_safe(isoLanguage, value, valueLength, &status);
+ return status;
}
/*
@@ -114,10 +115,10 @@ GetLocaleIso3166CountryName
Gets the country name for a locale (via uloc_getCountry) and converts the result to UChars
*/
-UErrorCode GetLocaleIso3166CountryName(const char* locale, UChar* value, int32_t valueLength)
+static UErrorCode GetLocaleIso3166CountryName(const char* locale, UChar* value, int32_t valueLength)
{
- UErrorCode status = U_ZERO_ERROR;
- int32_t length = uloc_getCountry(locale, NULL, 0, &status) + 1;
+ UErrorCode status = U_ZERO_ERROR, ignore = U_ZERO_ERROR;
+ int32_t length = uloc_getCountry(locale, NULL, 0, &ignore) + 1;
char* buf = calloc(length, sizeof(char));
if (buf == NULL)
@@ -125,15 +126,8 @@ UErrorCode GetLocaleIso3166CountryName(const char* locale, UChar* value, int32_t
return U_MEMORY_ALLOCATION_ERROR;
}
- status = U_ZERO_ERROR;
-
uloc_getCountry(locale, buf, length, &status);
-
- if (U_SUCCESS(status))
- {
- status = u_charsToUChars_safe(buf, value, valueLength);
- }
-
+ u_charsToUChars_safe(buf, value, valueLength, &status);
free(buf);
return status;
@@ -145,8 +139,9 @@ GetLocaleIso3166CountryCode
Gets the 3 letter country code for a locale (via uloc_getISO3Country) and converts the result to UChars
*/
-UErrorCode GetLocaleIso3166CountryCode(const char* locale, UChar* value, int32_t valueLength)
+static UErrorCode GetLocaleIso3166CountryCode(const char* locale, UChar* value, int32_t valueLength)
{
+ UErrorCode status = U_ZERO_ERROR;
const char *pIsoCountryName = uloc_getISO3Country(locale);
int len = strlen(pIsoCountryName);
@@ -155,7 +150,8 @@ UErrorCode GetLocaleIso3166CountryCode(const char* locale, UChar* value, int32_t
return U_ILLEGAL_ARGUMENT_ERROR;
}
- return u_charsToUChars_safe(pIsoCountryName, value, valueLength);
+ u_charsToUChars_safe(pIsoCountryName, value, valueLength, &status);
+ return status;
}
/*
@@ -164,7 +160,7 @@ GetLocaleCurrencyName
Gets the locale currency English or native name and convert the result to UChars
*/
-UErrorCode GetLocaleCurrencyName(const char* locale, bool nativeName, UChar* value, int32_t valueLength)
+static UErrorCode GetLocaleCurrencyName(const char* locale, UBool nativeName, UChar* value, int32_t valueLength)
{
UErrorCode status = U_ZERO_ERROR;
@@ -193,9 +189,10 @@ UErrorCode GetLocaleCurrencyName(const char* locale, bool nativeName, UChar* val
{
return U_BUFFER_OVERFLOW_ERROR;
}
+
u_strncpy(value, pCurrencyLongName, len);
value[len] = 0;
-
+
return status;
}
@@ -206,12 +203,14 @@ GetLocaleInfoString
Obtains string locale information.
Returns 1 for success, 0 otherwise
*/
-int32_t GlobalizationNative_GetLocaleInfoString(
- const UChar* localeName, LocaleStringData localeStringData, UChar* value, int32_t valueLength)
+int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName,
+ LocaleStringData localeStringData,
+ UChar* value,
+ int32_t valueLength)
{
UErrorCode status = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
- GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &status);
+ GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &status);
if (U_FAILURE(status))
{
@@ -269,10 +268,10 @@ int32_t GlobalizationNative_GetLocaleInfoString(
status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_INTL_CURRENCY_SYMBOL, value, valueLength);
break;
case CurrencyEnglishName:
- status = GetLocaleCurrencyName(locale, false, value, valueLength);
+ status = GetLocaleCurrencyName(locale, FALSE, value, valueLength);
break;
case CurrencyNativeName:
- status = GetLocaleCurrencyName(locale, true, value, valueLength);
+ status = GetLocaleCurrencyName(locale, TRUE, value, valueLength);
break;
case MonetaryDecimalSeparator:
status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_SEPARATOR_SYMBOL, value, valueLength);
@@ -282,10 +281,10 @@ int32_t GlobalizationNative_GetLocaleInfoString(
GetLocaleInfoDecimalFormatSymbol(locale, UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL, value, valueLength);
break;
case AMDesignator:
- status = GetLocaleInfoAmPm(locale, true, value, valueLength);
+ status = GetLocaleInfoAmPm(locale, TRUE, value, valueLength);
break;
case PMDesignator:
- status = GetLocaleInfoAmPm(locale, false, value, valueLength);
+ status = GetLocaleInfoAmPm(locale, FALSE, value, valueLength);
break;
case PositiveSign:
status = GetLocaleInfoDecimalFormatSymbol(locale, UNUM_PLUS_SIGN_SYMBOL, value, valueLength);
@@ -318,13 +317,10 @@ int32_t GlobalizationNative_GetLocaleInfoString(
char localeNameTemp[ULOC_FULLNAME_CAPACITY];
uloc_getParent(locale, localeNameTemp, ULOC_FULLNAME_CAPACITY, &status);
+ u_charsToUChars_safe(localeNameTemp, value, valueLength, &status);
if (U_SUCCESS(status))
{
- status = u_charsToUChars_safe(localeNameTemp, value, valueLength);
- if (U_SUCCESS(status))
- {
- FixupLocaleName(value, valueLength);
- }
+ FixupLocaleName(value, valueLength);
}
break;
}
@@ -349,15 +345,17 @@ GetLocaleTimeFormat
Obtains time format information (in ICU format, it needs to be coverted to .NET Format).
Returns 1 for success, 0 otherwise
*/
-int32_t GlobalizationNative_GetLocaleTimeFormat(
- const UChar* localeName, int shortFormat, UChar* value, int32_t valueLength)
+int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName,
+ int shortFormat,
+ UChar* value,
+ int32_t valueLength)
{
UErrorCode err = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
- GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
+ GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
UDateFormatStyle style = (shortFormat != 0) ? UDAT_SHORT : UDAT_MEDIUM;
UDateFormat* pFormat = udat_open(style, UDAT_NONE, locale, NULL, 0, NULL, 0, &err);
- udat_toPattern(pFormat, false, value, valueLength, &err);
+ udat_toPattern(pFormat, FALSE, value, valueLength, &err);
udat_close(pFormat);
return UErrorCodeToBool(err);
}
diff --git a/src/corefx/System.Globalization.Native/pal_timeZoneInfo.c b/src/corefx/System.Globalization.Native/pal_timeZoneInfo.c
index 1ea378b835..7ed2a2c3c3 100644
--- a/src/corefx/System.Globalization.Native/pal_timeZoneInfo.c
+++ b/src/corefx/System.Globalization.Native/pal_timeZoneInfo.c
@@ -11,12 +11,15 @@
/*
Gets the localized display name for the specified time zone.
*/
-ResultCode GlobalizationNative_GetTimeZoneDisplayName(
- const UChar* localeName, const UChar* timeZoneId, TimeZoneDisplayNameType type, UChar* result, int32_t resultLength)
+ResultCode GlobalizationNative_GetTimeZoneDisplayName(const UChar* localeName,
+ const UChar* timeZoneId,
+ TimeZoneDisplayNameType type,
+ UChar* result,
+ int32_t resultLength)
{
UErrorCode err = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
- GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, false, &err);
+ GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err);
int32_t timeZoneIdLength = -1; // timeZoneId is NULL-terminated
UCalendar* calendar = ucal_open(timeZoneId, timeZoneIdLength, locale, UCAL_DEFAULT, &err);