CF_PRIVATE UCalendar *__CFCalendarCreateUCalendar(CFStringRef calendarID, CFStringRef localeID, CFTimeZoneRef tz) { if (calendarID) { CFDictionaryRef components = CFLocaleCreateComponentsFromLocaleIdentifier(kCFAllocatorSystemDefault, localeID); CFMutableDictionaryRef mcomponents = CFDictionaryCreateMutableCopy(kCFAllocatorSystemDefault, 0, components); CFDictionarySetValue(mcomponents, kCFLocaleCalendarIdentifier, calendarID); localeID = CFLocaleCreateLocaleIdentifierFromComponents(kCFAllocatorSystemDefault, mcomponents); CFRelease(mcomponents); CFRelease(components); } char buffer[BUFFER_SIZE]; const char *cstr = CFStringGetCStringPtr(localeID, kCFStringEncodingASCII); if (NULL == cstr) { if (CFStringGetCString(localeID, buffer, BUFFER_SIZE, kCFStringEncodingASCII)) cstr = buffer; } if (NULL == cstr) { if (calendarID) CFRelease(localeID); return NULL; } UChar ubuffer[BUFFER_SIZE]; CFStringRef tznam = CFTimeZoneGetName(tz); CFIndex cnt = CFStringGetLength(tznam); if (BUFFER_SIZE < cnt) cnt = BUFFER_SIZE; CFStringGetCharacters(tznam, CFRangeMake(0, cnt), (UniChar *)ubuffer); UErrorCode status = U_ZERO_ERROR; UCalendar *cal = ucal_open(ubuffer, cnt, cstr, UCAL_DEFAULT, &status); if (calendarID) CFRelease(localeID); return cal; }
static CFStringRef createLocaleIDFromLocaleAndCalendar(CFLocaleRef locale, CFCalendarRef calendar) { CFMutableDictionaryRef dict; { CFDictionaryRef immutableDict = CFLocaleCreateComponentsFromLocaleIdentifier(kCFAllocatorSystemDefault, CFLocaleGetIdentifier(locale)); dict = CFDictionaryCreateMutableCopy(kCFAllocatorSystemDefault, 0, immutableDict); CFRelease(immutableDict); } if (calendar) { CFDictionarySetValue(dict, kCFLocaleCalendar, calendar); } CFStringRef localeID = CFLocaleCreateLocaleIdentifierFromComponents(kCFAllocatorSystemDefault, dict); CFRelease(dict); return localeID; }