UEnumeration* pEnum = ucal_getKeywordValuesForLocale("calendar", locale, TRUE, &err);
if (U_FAILURE(err))
- {
- uenum_close(pEnum);
return 0;
- }
int stringEnumeratorCount = uenum_count(pEnum, &err);
if (U_FAILURE(err))
UDateTimePatternGenerator* pGenerator = udatpg_open(locale, &err);
if (U_FAILURE(err))
- {
- udatpg_close(pGenerator);
return GetResultCode(err);
- }
udatpg_getBestPattern(pGenerator, UDAT_MONTH_DAY_UCHAR, -1, sMonthDay, stringCapacity, &err);
UDateFormat* pFormat = udat_open(UDAT_NONE, style, locale, NULL, 0, NULL, 0, &err);
if (U_FAILURE(err))
- {
- unum_close(pFormat);
return false;
- }
UErrorCode ignore = U_ZERO_ERROR;
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;
}
udat_toPattern(pFormat, false, pattern, patternLen, &err);
-
udat_close(pFormat);
if (U_SUCCESS(err))
UDateTimePatternGenerator* pGenerator = udatpg_open(locale, &err);
if (U_FAILURE(err))
- {
- udatpg_close(pGenerator);
return false;
- }
UErrorCode ignore = U_ZERO_ERROR;
int32_t patternLen = udatpg_getBestPattern(pGenerator, patternSkeleton, -1, NULL, 0, &ignore) + 1;
UChar* bestPattern = calloc(patternLen, sizeof(UChar));
if (bestPattern == NULL)
{
+ udatpg_close(pGenerator);
return false;
}
udatpg_getBestPattern(pGenerator, patternSkeleton, -1, bestPattern, patternLen, &err);
-
udatpg_close(pGenerator);
+
if (U_SUCCESS(err))
{
callback(bestPattern, context);
UDateFormat* pFormat = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, locale, NULL, 0, NULL, 0, &err);
if (U_FAILURE(err))
- {
- udat_close(pFormat);
return false;
- }
char localeWithCalendarName[ULOC_FULLNAME_CAPACITY];
strncpy(localeWithCalendarName, locale, ULOC_FULLNAME_CAPACITY);
if (symbolBuf == NULL)
{
udat_close(pFormat);
- free(symbolBuf);
+ ucal_close(pCalendar);
return false;
}
if (U_FAILURE(err))
{
udat_close(pFormat);
+ ucal_close(pCalendar);
free(symbolBuf);
return false;
}
}
udat_close(pFormat);
+ ucal_close(pCalendar);
return true;
}
UCalendar* pCal = ucal_open(NULL, 0, JAPANESE_LOCALE_AND_CALENDAR, UCAL_TRADITIONAL, &err);
if (U_FAILURE(err))
- {
- ucal_close(pCal);
return 0;
- }
ucal_set(pCal, UCAL_EXTENDED_YEAR, 9999);
int32_t ret = ucal_get(pCal, UCAL_ERA, &err);
UCalendar* pCal = ucal_open(NULL, 0, JAPANESE_LOCALE_AND_CALENDAR, UCAL_TRADITIONAL, &err);
if (U_FAILURE(err))
- {
- ucal_close(pCal);
return false;
- }
ucal_set(pCal, UCAL_ERA, era);
ucal_set(pCal, UCAL_YEAR, 1);
{
const TCollatorMap* leftMap = left;
const TCollatorMap* rightMap = right;
- return leftMap->key - rightMap->key;
+ if (leftMap->key < rightMap->key) return -1;
+ if (leftMap->key > rightMap->key) return 1;
+ return 0;
}
// Hiragana character range
static bool AddItem(UCharList* list, size_t* currentCapacity, const UChar item)
{
size_t size = list->size++;
- if(size >= *currentCapacity)
+ if (size >= *currentCapacity)
{
*currentCapacity *= 2;
UChar* ptr = (UChar*)realloc(list->items, *currentCapacity * sizeof(UChar*));
- if(ptr == NULL)
+ if (ptr == NULL)
{
return false;
}
}
pClonedCollator = ucol_openRules(completeRules, completeRulesLength, UCOL_DEFAULT, strength, NULL, pErr);
+ free(customRules);
}
if (isIgnoreSymbols)
}
-ResultCode GlobalizationNative_GetSortHandle(const char* lpLocaleName, SortHandle** ppSortHandle)
+void CreateSortHandle(SortHandle** ppSortHandle)
{
- assert(ppSortHandle != NULL);
-
*ppSortHandle = (SortHandle*)malloc(sizeof(SortHandle));
if ((*ppSortHandle) == NULL)
{
- return GetResultCode(U_MEMORY_ALLOCATION_ERROR);
+ return;
}
(*ppSortHandle)->pRoot = NULL;
int result = pthread_mutex_init(&(*ppSortHandle)->collatorsLockObject, NULL);
+
if (result != 0)
{
assert(false && "Unexpected pthread_mutex_init return value.");
}
+}
+
+ResultCode GlobalizationNative_GetSortHandle(const char* lpLocaleName, SortHandle** ppSortHandle)
+{
+ assert(ppSortHandle != NULL);
+
+ CreateSortHandle(ppSortHandle);
+ if ((*ppSortHandle) == NULL)
+ {
+ return GetResultCode(U_MEMORY_ALLOCATION_ERROR);
+ }
UErrorCode err = U_ZERO_ERROR;
if (U_FAILURE(err))
{
- if ((*ppSortHandle)->regular != NULL)
- ucol_close((*ppSortHandle)->regular);
-
free(*ppSortHandle);
(*ppSortHandle) = NULL;
}
}
else
{
+ free(map);
pCollator = (*(TCollatorMap**)entry)->UCollator;
}
IndexOf
*/
int32_t GlobalizationNative_IndexOf(
- SortHandle* pSortHandle,
- const UChar* lpTarget,
- int32_t cwTargetLength,
- const UChar* lpSource,
- int32_t cwSourceLength,
+ SortHandle* pSortHandle,
+ const UChar* lpTarget,
+ int32_t cwTargetLength,
+ const UChar* lpSource,
+ int32_t cwSourceLength,
int32_t options,
int32_t* pMatchedLength)
{
// if the search was successful,
// we'll try to get the matched string length.
if(result != USEARCH_DONE && pMatchedLength != NULL)
- {
- *pMatchedLength = usearch_getMatchedLength(pSearch);
+ {
+ *pMatchedLength = usearch_getMatchedLength(pSearch);
}
usearch_close(pSearch);
}
LastIndexOf
*/
int32_t GlobalizationNative_LastIndexOf(
- SortHandle* pSortHandle,
- const UChar* lpTarget,
- int32_t cwTargetLength,
- const UChar* lpSource,
- int32_t cwSourceLength,
+ SortHandle* pSortHandle,
+ const UChar* lpTarget,
+ int32_t cwTargetLength,
+ const UChar* lpSource,
+ int32_t cwSourceLength,
int32_t options)
{
static_assert(USEARCH_DONE == -1, "managed side requires -1 for not found");
Return value is a "Win32 BOOL" (1 = true, 0 = false)
*/
int32_t GlobalizationNative_StartsWith(
- SortHandle* pSortHandle,
- const UChar* lpTarget,
- int32_t cwTargetLength,
- const UChar* lpSource,
- int32_t cwSourceLength,
+ SortHandle* pSortHandle,
+ const UChar* lpTarget,
+ int32_t cwTargetLength,
+ const UChar* lpSource,
+ int32_t cwSourceLength,
int32_t options)
{
int32_t result = FALSE;
Return value is a "Win32 BOOL" (1 = true, 0 = false)
*/
int32_t GlobalizationNative_EndsWith(
- SortHandle* pSortHandle,
- const UChar* lpTarget,
- int32_t cwTargetLength,
- const UChar* lpSource,
- int32_t cwSourceLength,
+ SortHandle* pSortHandle,
+ const UChar* lpTarget,
+ int32_t cwTargetLength,
+ const UChar* lpSource,
+ int32_t cwSourceLength,
int32_t options)
{
int32_t result = FALSE;
}
int32_t GlobalizationNative_GetSortKey(
- SortHandle* pSortHandle,
- const UChar* lpStr,
- int32_t cwStrLength,
- uint8_t* sortKey,
- int32_t cbSortKeyLength,
+ SortHandle* pSortHandle,
+ const UChar* lpStr,
+ int32_t cwStrLength,
+ uint8_t* sortKey,
+ int32_t cbSortKeyLength,
int32_t options)
{
UErrorCode err = U_ZERO_ERROR;
UNumberFormat* pFormat = unum_open(UNUM_DECIMAL, NULL, 0, locale, NULL, &status);
if (U_FAILURE(status))
- {
- unum_close(pFormat);
return status;
- }
unum_getSymbol(pFormat, symbol, value, valueLength, &status);
UDateFormat* pFormat = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, locale, NULL, 0, NULL, 0, &status);
if (U_FAILURE(status))
- {
- udat_close(pFormat);
return status;
- }
udat_getSymbols(pFormat, UDAT_AM_PMS, am ? 0 : 1, value, valueLength, &status);
UDateFormat* pFormat = udat_open(style, UDAT_NONE, locale, NULL, 0, NULL, 0, &err);
if (U_FAILURE(err))
- {
- udat_close(pFormat);
return UErrorCodeToBool(err);
- }
udat_toPattern(pFormat, false, value, valueLength, &err);