MCPcopy Create free account
hub / github.com/MailCore/mailcore2 / prepare

Method prepare

src/core/renderer/MCDateFormatter.cpp:204–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202#endif
203
204void DateFormatter::prepare()
205{
206#if USE_COREFOUNDATION
207 if (mAppleDateFormatter != NULL)
208 return;
209
210 CFStringRef localeIdentifier = NULL;
211 CFLocaleRef localeRef = NULL;
212 if (mLocale != NULL) {
213 localeIdentifier = CFStringCreateWithCharacters(NULL, (const UniChar *) mLocale->unicodeCharacters(),
214 mLocale->length());
215 localeRef = CFLocaleCreate(NULL, localeIdentifier);
216 }
217 if (localeRef == NULL) {
218 localeRef = CFLocaleCopyCurrent();
219 }
220 mAppleDateFormatter = CFDateFormatterCreate(NULL, localeRef, toAppleStyle(mDateStyle), toAppleStyle(mTimeStyle));
221 if (mDateFormat != NULL) {
222 CFStringRef dateFormatCFString = CFStringCreateWithCharacters(NULL, (const UniChar *) mDateFormat->unicodeCharacters(),
223 mDateFormat->length());
224 CFDateFormatterSetFormat((CFDateFormatterRef) mAppleDateFormatter, dateFormatCFString);
225 CFRelease(dateFormatCFString);
226 }
227 if (localeIdentifier != NULL) {
228 CFRelease(localeIdentifier);
229 }
230 if (localeRef != NULL) {
231 CFRelease(localeRef);
232 }
233#else
234 if (mDateFormatter != NULL)
235 return;
236
237 const UChar * tzID = NULL;
238 int32_t tzIDLength = -1;
239 const UChar * pattern = NULL;
240 int32_t patternLength = -1;
241 UErrorCode err = U_ZERO_ERROR;
242 const char * locale = NULL;
243
244 if (mTimezone != NULL) {
245 tzID = mTimezone->unicodeCharacters();
246 tzIDLength = mTimezone->length();
247 }
248 if (mDateFormat != NULL) {
249 pattern = mDateFormat->unicodeCharacters();
250 patternLength = mDateFormat->length();
251 }
252 if (mLocale != NULL) {
253 locale = mLocale->UTF8Characters();
254 }
255
256 mDateFormatter = udat_open((UDateFormatStyle) mTimeStyle, (UDateFormatStyle) mDateStyle,
257 locale,
258 tzID, tzIDLength,
259 pattern, patternLength,
260 &err);
261#endif

Callers

nothing calls this directly

Calls 4

toAppleStyleFunction · 0.85
unicodeCharactersMethod · 0.80
UTF8CharactersMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected