Gets the associated ICU calendar name for the CalendarId.
*/
-const char* GetCalendarName(CalendarId calendarId)
+static const char* GetCalendarName(CalendarId calendarId)
{
switch (calendarId)
{
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?
{
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;
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);
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);
{
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;
case MonthDay:
return GetMonthDayPattern(locale, result, resultCapacity);
default:
- assert(false);
+ assert(FALSE);
return UnknownError;
}
}
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))
}
free(pattern);
- return U_SUCCESS(err);
+ return UErrorCodeToBool(err);
}
/*
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;
if (bestPattern == NULL)
{
udatpg_close(pGenerator);
- return false;
+ return FALSE;
}
udatpg_getBestPattern(pGenerator, patternSkeleton, -1, bestPattern, patternLen, &err);
}
free(bestPattern);
- return U_SUCCESS(err);
+ return UErrorCodeToBool(err);
}
/*
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);
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);
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);
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
strncpy(localeNamePtr, locale, ULOC_FULLNAME_CAPACITY);
- while (true)
+ while (TRUE)
{
UErrorCode status = U_ZERO_ERROR;
char* name = GetCalendarName(calendarId);
{
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.
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)
{
case AbbrevEraNames:
return EnumAbbrevEraNames(locale, calendarId, callback, context);
default:
- assert(false);
- return false;
+ assert(FALSE);
+ return FALSE;
}
}
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;
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);
if (U_FAILURE(err))
{
ucal_close(pCal);
- return false;
+ return FALSE;
}
// set the date to Jan 1
*startDay = ucal_get(pCal, UCAL_DATE, &err);
ucal_close(pCal);
- return U_SUCCESS(err);
+ return UErrorCodeToBool(err);
}
}
}
}
ucal_close(pCal);
- return false;
+ return FALSE;
}
#include <assert.h>
#include <pthread.h>
#include <stdlib.h>
-#include <stdbool.h>
#include <stdint.h>
#include <search.h>
#include <string.h>
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)
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)
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;
}
/*
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;
UChar lowerChar;
UChar higherChar;
- bool needsEscape;
+ int needsEscape;
for (int i = 0; i < g_HalfFullCharsLength; i++)
{
lowerChar = g_HalfFullLowerChars[i];
{
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)
{
}
// 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;
}
if (result != 0)
{
- assert(false && "Unexpected pthread_mutex_init return value.");
+ assert(FALSE && "Unexpected pthread_mutex_init return value.");
}
}
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));
}
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;
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)
// 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);
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;
}
}
#include <dlfcn.h>
#include <stdlib.h>
-#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#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");
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__
// 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);
}
}
-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
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];
// 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)
{
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).
// 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
{
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--)
{
{
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--)
{
{
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) ||
if (!FindICULibs(VERSION_PREFIX_SUSE, symbolName, symbolVersion))
#endif
{
- return 0;
+ return FALSE;
}
}
libicui18n = NULL;
#endif // __APPLE__
- return 1;
+ return TRUE;
}
// GlobalizationNative_GetICUVersion
{
if (U_SUCCESS(status))
{
- return 1;
+ return TRUE;
}
// assert errors that should never occur
// 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++)
{
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)
return i;
}
-bool IsEnvVarSet(const char* name)
+static int IsEnvVarSet(const char* name)
{
const char* value = getenv(name);
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);
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);
}
}
// 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"
/*
int32_t GetLocale(const UChar* localeName,
char* localeNameResult,
int32_t localeNameResultLength,
- bool canonicalize,
+ UBool canonicalize,
UErrorCode* err);
/*
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:
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:
#include <assert.h>
#include <stdlib.h>
-#include <stdbool.h>
#include <string.h>
#include "pal_localeNumberData.h"
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);
}
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++)
{
case UCHAR_MINUS:
case UCHAR_OPENPAREN:
case UCHAR_CLOSEPAREN:
- minusAdded = true;
+ minusAdded = TRUE;
break;
}
}
case UCHAR_DIGIT:
if (!digitAdded)
{
- digitAdded = true;
+ digitAdded = TRUE;
destPattern[index++] = 'n';
}
break;
case UCHAR_CURRENCY:
if (!currencyAdded)
{
- currencyAdded = true;
+ currencyAdded = TRUE;
destPattern[index++] = 'C';
}
break;
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;
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)
UErrorCode err = U_ZERO_ERROR;
- unum_toPattern(pNumberFormat, false, icuPattern, icuPatternLength, &err);
+ unum_toPattern(pNumberFormat, FALSE, icuPattern, icuPatternLength, &err);
assert(U_SUCCESS(err));
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;
}
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)",
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);
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"};
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);
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 -"};
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);
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[] = {
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);
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"};
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);
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;
{
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)
break;
default:
status = U_UNSUPPORTED_ERROR;
- assert(false);
+ assert(FALSE);
break;
}
{
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))
{
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);
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))
{
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);
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;
}
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;
}
/*
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)
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;
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);
return U_ILLEGAL_ARGUMENT_ERROR;
}
- return u_charsToUChars_safe(pIsoCountryName, value, valueLength);
+ u_charsToUChars_safe(pIsoCountryName, value, valueLength, &status);
+ return status;
}
/*
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;
{
return U_BUFFER_OVERFLOW_ERROR;
}
+
u_strncpy(value, pCurrencyLongName, len);
value[len] = 0;
-
+
return status;
}
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))
{
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);
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);
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;
}
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);
}
/*
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);