#endif
DateIntervalInfo* dtitvinf = new DateIntervalInfo(locale, status);
+ if (dtitvinf == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return nullptr;
+ }
return create(locale, dtitvinf, &skeleton, status);
}
DateIntervalFormat::DateIntervalFormat()
-: fInfo(NULL),
- fDateFormat(NULL),
- fFromCalendar(NULL),
- fToCalendar(NULL),
+: fInfo(nullptr),
+ fDateFormat(nullptr),
+ fFromCalendar(nullptr),
+ fToCalendar(nullptr),
fLocale(Locale::getRoot()),
- fDatePattern(NULL),
- fTimePattern(NULL),
- fDateTimeFormat(NULL)
+ fDatePattern(nullptr),
+ fTimePattern(nullptr),
+ fDateTimeFormat(nullptr)
{}
DateIntervalFormat::DateIntervalFormat(const DateIntervalFormat& itvfmt)
: Format(itvfmt),
- fInfo(NULL),
- fDateFormat(NULL),
- fFromCalendar(NULL),
- fToCalendar(NULL),
+ fInfo(nullptr),
+ fDateFormat(nullptr),
+ fFromCalendar(nullptr),
+ fToCalendar(nullptr),
fLocale(itvfmt.fLocale),
- fDatePattern(NULL),
- fTimePattern(NULL),
- fDateTimeFormat(NULL) {
+ fDatePattern(nullptr),
+ fTimePattern(nullptr),
+ fDateTimeFormat(nullptr) {
*this = itvfmt;
}
if ( itvfmt.fDateFormat ) {
fDateFormat = itvfmt.fDateFormat->clone();
} else {
- fDateFormat = NULL;
+ fDateFormat = nullptr;
}
if ( itvfmt.fFromCalendar ) {
fFromCalendar = itvfmt.fFromCalendar->clone();
} else {
- fFromCalendar = NULL;
+ fFromCalendar = nullptr;
}
if ( itvfmt.fToCalendar ) {
fToCalendar = itvfmt.fToCalendar->clone();
} else {
- fToCalendar = NULL;
+ fToCalendar = nullptr;
}
}
if ( itvfmt.fInfo ) {
fInfo = itvfmt.fInfo->clone();
} else {
- fInfo = NULL;
+ fInfo = nullptr;
}
fSkeleton = itvfmt.fSkeleton;
int8_t i;
fIntervalPatterns[i] = itvfmt.fIntervalPatterns[i];
}
fLocale = itvfmt.fLocale;
- fDatePattern = (itvfmt.fDatePattern)? itvfmt.fDatePattern->clone(): NULL;
- fTimePattern = (itvfmt.fTimePattern)? itvfmt.fTimePattern->clone(): NULL;
- fDateTimeFormat = (itvfmt.fDateTimeFormat)? itvfmt.fDateTimeFormat->clone(): NULL;
+ fDatePattern = (itvfmt.fDatePattern)? itvfmt.fDatePattern->clone(): nullptr;
+ fTimePattern = (itvfmt.fTimePattern)? itvfmt.fTimePattern->clone(): nullptr;
+ fDateTimeFormat = (itvfmt.fDateTimeFormat)? itvfmt.fDateTimeFormat->clone(): nullptr;
}
return *this;
}
const DateIntervalFormat* fmt = (DateIntervalFormat*)&other;
if (this == fmt) {return TRUE;}
if (!Format::operator==(other)) {return FALSE;}
- if ((fInfo != fmt->fInfo) && (fInfo == NULL || fmt->fInfo == NULL)) {return FALSE;}
+ if ((fInfo != fmt->fInfo) && (fInfo == nullptr || fmt->fInfo == nullptr)) {return FALSE;}
if (fInfo && fmt->fInfo && (*fInfo != *fmt->fInfo )) {return FALSE;}
{
Mutex lock(&gFormatterMutex);
- if (fDateFormat != fmt->fDateFormat && (fDateFormat == NULL || fmt->fDateFormat == NULL)) {return FALSE;}
+ if (fDateFormat != fmt->fDateFormat && (fDateFormat == nullptr || fmt->fDateFormat == nullptr)) {return FALSE;}
if (fDateFormat && fmt->fDateFormat && (*fDateFormat != *fmt->fDateFormat)) {return FALSE;}
}
// note: fFromCalendar and fToCalendar hold no persistent state, and therefore do not participate in operator ==.
// fDateFormat has the master calendar for the DateIntervalFormat.
if (fSkeleton != fmt->fSkeleton) {return FALSE;}
- if (fDatePattern != fmt->fDatePattern && (fDatePattern == NULL || fmt->fDatePattern == NULL)) {return FALSE;}
+ if (fDatePattern != fmt->fDatePattern && (fDatePattern == nullptr || fmt->fDatePattern == nullptr)) {return FALSE;}
if (fDatePattern && fmt->fDatePattern && (*fDatePattern != *fmt->fDatePattern)) {return FALSE;}
- if (fTimePattern != fmt->fTimePattern && (fTimePattern == NULL || fmt->fTimePattern == NULL)) {return FALSE;}
+ if (fTimePattern != fmt->fTimePattern && (fTimePattern == nullptr || fmt->fTimePattern == nullptr)) {return FALSE;}
if (fTimePattern && fmt->fTimePattern && (*fTimePattern != *fmt->fTimePattern)) {return FALSE;}
- if (fDateTimeFormat != fmt->fDateTimeFormat && (fDateTimeFormat == NULL || fmt->fDateTimeFormat == NULL)) {return FALSE;}
+ if (fDateTimeFormat != fmt->fDateTimeFormat && (fDateTimeFormat == nullptr || fmt->fDateTimeFormat == nullptr)) {return FALSE;}
if (fDateTimeFormat && fmt->fDateTimeFormat && (*fDateTimeFormat != *fmt->fDateTimeFormat)) {return FALSE;}
if (fLocale != fmt->fLocale) {return FALSE;}
if ( obj.getType() == Formattable::kObject ) {
const UObject* formatObj = obj.getObject();
const DateInterval* interval = dynamic_cast<const DateInterval*>(formatObj);
- if (interval != NULL) {
+ if (interval != nullptr) {
return format(interval, appendTo, fieldPosition, status);
}
}
if ( U_FAILURE(status) ) {
return appendTo;
}
- if (fDateFormat == NULL || fInfo == NULL) {
+ if (fDateFormat == nullptr || fInfo == nullptr) {
status = U_INVALID_STATE_ERROR;
return appendTo;
}
FormattedDateInterval DateIntervalFormat::formatToValue(
const DateInterval& dtInterval,
UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return FormattedDateInterval(status);
+ }
+ // LocalPointer only sets OOM status if U_SUCCESS is true.
LocalPointer<FormattedDateIntervalData> result(new FormattedDateIntervalData(status), status);
if (U_FAILURE(status)) {
return FormattedDateInterval(status);
Calendar& fromCalendar,
Calendar& toCalendar,
UErrorCode& status) const {
+ if (U_FAILURE(status)) {
+ return FormattedDateInterval(status);
+ }
+ // LocalPointer only sets OOM status if U_SUCCESS is true.
LocalPointer<FormattedDateIntervalData> result(new FormattedDateIntervalData(status), status);
if (U_FAILURE(status)) {
return FormattedDateInterval(status);
UErrorCode& status) {
delete fInfo;
fInfo = new DateIntervalInfo(newItvPattern);
+ if (fInfo == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ }
// Delete patterns that get reset by initializePattern
delete fDatePattern;
- fDatePattern = NULL;
+ fDatePattern = nullptr;
delete fTimePattern;
- fTimePattern = NULL;
+ fTimePattern = nullptr;
delete fDateTimeFormat;
- fDateTimeFormat = NULL;
+ fDateTimeFormat = nullptr;
if (fDateFormat) {
initializePattern(status);
void
DateIntervalFormat::adoptTimeZone(TimeZone* zone)
{
- if (fDateFormat != NULL) {
+ if (fDateFormat != nullptr) {
fDateFormat->adoptTimeZone(zone);
}
// The fDateFormat has the master calendar for the DateIntervalFormat and has
void
DateIntervalFormat::setTimeZone(const TimeZone& zone)
{
- if (fDateFormat != NULL) {
+ if (fDateFormat != nullptr) {
fDateFormat->setTimeZone(zone);
}
// The fDateFormat has the master calendar for the DateIntervalFormat;
const TimeZone&
DateIntervalFormat::getTimeZone() const
{
- if (fDateFormat != NULL) {
+ if (fDateFormat != nullptr) {
Mutex lock(&gFormatterMutex);
return fDateFormat->getTimeZone();
}
- // If fDateFormat is NULL (unexpected), create default timezone.
+ // If fDateFormat is nullptr (unexpected), create default timezone.
return *(TimeZone::createDefault());
}
DateIntervalInfo* dtItvInfo,
const UnicodeString* skeleton,
UErrorCode& status)
-: fInfo(NULL),
- fDateFormat(NULL),
- fFromCalendar(NULL),
- fToCalendar(NULL),
+: fInfo(nullptr),
+ fDateFormat(nullptr),
+ fFromCalendar(nullptr),
+ fToCalendar(nullptr),
fLocale(locale),
- fDatePattern(NULL),
- fTimePattern(NULL),
- fDateTimeFormat(NULL)
+ fDatePattern(nullptr),
+ fTimePattern(nullptr),
+ fDateTimeFormat(nullptr)
{
LocalPointer<DateIntervalInfo> info(dtItvInfo, status);
LocalPointer<SimpleDateFormat> dtfmt(static_cast<SimpleDateFormat *>(
UErrorCode& status) {
DateIntervalFormat* f = new DateIntervalFormat(locale, dtitvinf,
skeleton, status);
- if ( f == NULL ) {
+ if ( f == nullptr ) {
status = U_MEMORY_ALLOCATION_ERROR;
delete dtitvinf;
} else if ( U_FAILURE(status) ) {
// with the time interval.
// The date/time pattern ( such as {0} {1} ) is saved in
// calendar, that is why need to get the CalendarData here.
- LocalUResourceBundlePointer dateTimePatternsRes(ures_open(NULL, locale.getBaseName(), &status));
+ LocalUResourceBundlePointer dateTimePatternsRes(ures_open(nullptr, locale.getBaseName(), &status));
ures_getByKey(dateTimePatternsRes.getAlias(), gCalendarTag,
dateTimePatternsRes.getAlias(), &status);
ures_getByKeyWithFallback(dateTimePatternsRes.getAlias(), gGregorianTag,
&dateTimeFormatLength, &status);
if ( U_SUCCESS(status) && dateTimeFormatLength >= 3 ) {
fDateTimeFormat = new UnicodeString(dateTimeFormat, dateTimeFormatLength);
+ if (fDateTimeFormat == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
}
}
// the first part of the pattern is empty,
// the second part of the pattern is the full-pattern
// should be used in fall-back.
- setPatternInfo(UCAL_DATE, NULL, &pattern, fInfo->getDefaultOrder());
- setPatternInfo(UCAL_MONTH, NULL, &pattern, fInfo->getDefaultOrder());
- setPatternInfo(UCAL_YEAR, NULL, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_DATE, nullptr, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_MONTH, nullptr, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_YEAR, nullptr, &pattern, fInfo->getDefaultOrder());
} else {
// TODO: fall back
}
// the first part of the pattern is empty,
// the second part of the pattern is the full-pattern
// should be used in fall-back.
- setPatternInfo(UCAL_DATE, NULL, &pattern, fInfo->getDefaultOrder());
- setPatternInfo(UCAL_MONTH, NULL, &pattern, fInfo->getDefaultOrder());
- setPatternInfo(UCAL_YEAR, NULL, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_DATE, nullptr, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_MONTH, nullptr, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(UCAL_YEAR, nullptr, &pattern, fInfo->getDefaultOrder());
} else {
/* if both present,
* 1) when the year, month, or day differs,
* range expression for the time.
*/
- if ( fDateTimeFormat == NULL ) {
+ if ( fDateTimeFormat == nullptr ) {
// earlier failure getting dateTimeFormat
return;
}
int8_t differenceInfo = 0;
const UnicodeString* bestSkeleton = fInfo->getBestSkeleton(*skeleton,
differenceInfo);
- /* best skeleton could be NULL.
+ /* best skeleton could be nullptr.
For example: in "ca" resource file,
interval format is defined as following
intervalFormats{
fallback{"{0} - {1}"}
}
there is no skeletons/interval patterns defined,
- and the best skeleton match could be NULL
+ and the best skeleton match could be nullptr
*/
- if ( bestSkeleton == NULL ) {
+ if ( bestSkeleton == nullptr ) {
return false;
}
status = U_ZERO_ERROR;
fDatePattern = new UnicodeString(DateFormat::getBestPattern(
fLocale, dateSkeleton, status));
+ // no way to report OOM. :(
}
if ( timeSkeleton.length() != 0) {
status = U_ZERO_ERROR;
fTimePattern = new UnicodeString(DateFormat::getBestPattern(
fLocale, timeSkeleton, status));
+ // no way to report OOM. :(
}
// difference:
if ( U_FAILURE(status) ) {
return;
}
- setPatternInfo(field, NULL, &pattern, fInfo->getDefaultOrder());
+ setPatternInfo(field, nullptr, &pattern, fInfo->getDefaultOrder());
}
DateIntervalInfo::DateIntervalInfo(UErrorCode& status)
: fFallbackIntervalPattern(gDefaultFallbackPattern),
fFirstDateInPtnIsLaterDate(false),
- fIntervalPatterns(NULL)
+ fIntervalPatterns(nullptr)
{
fIntervalPatterns = initHash(status);
}
DateIntervalInfo::DateIntervalInfo(const Locale& locale, UErrorCode& status)
: fFallbackIntervalPattern(gDefaultFallbackPattern),
fFirstDateInPtnIsLaterDate(false),
- fIntervalPatterns(NULL)
+ fIntervalPatterns(nullptr)
{
initializeData(locale, status);
}
DateIntervalInfo::DateIntervalInfo(const DateIntervalInfo& dtitvinf)
: UObject(dtitvinf),
- fIntervalPatterns(NULL)
+ fIntervalPatterns(nullptr)
{
*this = dtitvinf;
}
DateIntervalInfo::~DateIntervalInfo() {
deleteHash(fIntervalPatterns);
- fIntervalPatterns = NULL;
+ fIntervalPatterns = nullptr;
}
}
const UnicodeString* patternsOfOneSkeleton = (UnicodeString*) fIntervalPatterns->get(skeleton);
- if ( patternsOfOneSkeleton != NULL ) {
+ if ( patternsOfOneSkeleton != nullptr ) {
IntervalPatternIndex index = calendarFieldToIntervalIndex(field, status);
if ( U_FAILURE(status) ) {
return result;
UnicodeString* patternsOfOneSkeleton =
(UnicodeString*)(dateIntervalInfo.fIntervalPatterns->get(skeleton));
- if (patternsOfOneSkeleton == NULL || patternsOfOneSkeleton[index].isEmpty()) {
+ if (patternsOfOneSkeleton == nullptr || patternsOfOneSkeleton[index].isEmpty()) {
UnicodeString pattern = value.getUnicodeString(errorCode);
dateIntervalInfo.setIntervalPatternInternally(skeleton, lrgDiffCalUnit,
pattern, errorCode);
char calendarType[ULOC_KEYWORDS_CAPACITY]; // to be filled in with the type to use, if all goes well
char localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY];
// obtain a locale that always has the calendar key value that should be used
- (void)ures_getFunctionalEquivalent(localeWithCalendarKey, ULOC_LOCALE_IDENTIFIER_CAPACITY, NULL,
- "calendar", "calendar", locName, NULL, FALSE, &status);
+ (void)ures_getFunctionalEquivalent(localeWithCalendarKey, ULOC_LOCALE_IDENTIFIER_CAPACITY, nullptr,
+ "calendar", "calendar", locName, nullptr, FALSE, &status);
localeWithCalendarKey[ULOC_LOCALE_IDENTIFIER_CAPACITY-1] = 0; // ensure null termination
// now get the calendar key value from that locale
int32_t calendarTypeLen = uloc_getKeywordValue(localeWithCalendarKey, "calendar", calendarType,
// Instantiate the resource bundles
UResourceBundle *rb, *calBundle;
- rb = ures_open(NULL, locName, &status);
+ rb = ures_open(nullptr, locName, &status);
if (U_FAILURE(status)) {
return;
}
- calBundle = ures_getByKeyWithFallback(rb, gCalendarTag, NULL, &status);
+ calBundle = ures_getByKeyWithFallback(rb, gCalendarTag, nullptr, &status);
if (U_SUCCESS(status)) {
// Get the fallback pattern
const UChar* resStr = nullptr;
int32_t resStrLen = 0;
- calTypeBundle = ures_getByKeyWithFallback(calBundle, calendarTypeToUse, NULL, &status);
+ calTypeBundle = ures_getByKeyWithFallback(calBundle, calendarTypeToUse, nullptr, &status);
itvDtPtnResource = ures_getByKeyWithFallback(calTypeBundle,
- gIntervalDateTimePatternTag, NULL, &status);
+ gIntervalDateTimePatternTag, nullptr, &status);
// TODO(ICU-20400): After the fixing, we should find the "fallback" from
// the rb directly by the path "calendar/${calendar}/intervalFormats/fallback".
if ( U_SUCCESS(status) ) {
// ures_getByKeyWithFallback
UErrorCode localStatus = U_ZERO_ERROR;
UResourceBundle *genericCalBundle =
- ures_getByKeyWithFallback(calBundle, gGenericTag, NULL, &localStatus);
+ ures_getByKeyWithFallback(calBundle, gGenericTag, nullptr, &localStatus);
UResourceBundle *genericItvDtPtnResource =
ures_getByKeyWithFallback(
- genericCalBundle, gIntervalDateTimePatternTag, NULL, &localStatus);
+ genericCalBundle, gIntervalDateTimePatternTag, nullptr, &localStatus);
resStr = ures_getStringByKeyWithFallback(
genericItvDtPtnResource, gFallbackPatternTag, &resStrLen, &localStatus);
ures_close(genericItvDtPtnResource);
}
UnicodeString* patternsOfOneSkeleton = (UnicodeString*)(fIntervalPatterns->get(skeleton));
UBool emptyHash = false;
- if ( patternsOfOneSkeleton == NULL ) {
+ if ( patternsOfOneSkeleton == nullptr ) {
patternsOfOneSkeleton = new UnicodeString[kIPI_MAX_INDEX];
+ if (patternsOfOneSkeleton == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
emptyHash = true;
}
parseSkeleton(*inputSkeleton, inputSkeletonFieldWidth);
int32_t bestDistance = MAX_POSITIVE_INT;
- const UnicodeString* bestSkeleton = NULL;
+ const UnicodeString* bestSkeleton = nullptr;
// 0 means exact the same skeletons;
// 1 means having the same field, but with different length,
int8_t fieldLength = UPRV_LENGTHOF(skeletonFieldWidth);
int32_t pos = UHASH_FIRST;
- const UHashElement* elem = NULL;
- while ( (elem = fIntervalPatterns->nextElement(pos)) != NULL ) {
+ const UHashElement* elem = nullptr;
+ while ( (elem = fIntervalPatterns->nextElement(pos)) != nullptr ) {
const UHashTok keyTok = elem->key;
UnicodeString* newSkeleton = (UnicodeString*)keyTok.pointer;
#ifdef DTITVINF_DEBUG
void
DateIntervalInfo::deleteHash(Hashtable* hTable)
{
- if ( hTable == NULL ) {
+ if ( hTable == nullptr ) {
return;
}
int32_t pos = UHASH_FIRST;
- const UHashElement* element = NULL;
- while ( (element = hTable->nextElement(pos)) != NULL ) {
+ const UHashElement* element = nullptr;
+ while ( (element = hTable->nextElement(pos)) != nullptr ) {
const UHashTok valueTok = element->value;
const UnicodeString* value = (UnicodeString*)valueTok.pointer;
delete[] value;
Hashtable*
DateIntervalInfo::initHash(UErrorCode& status) {
if ( U_FAILURE(status) ) {
- return NULL;
+ return nullptr;
}
Hashtable* hTable;
- if ( (hTable = new Hashtable(FALSE, status)) == NULL ) {
+ if ( (hTable = new Hashtable(FALSE, status)) == nullptr ) {
status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ return nullptr;
}
if ( U_FAILURE(status) ) {
delete hTable;
- return NULL;
+ return nullptr;
}
hTable->setValueComparator(dtitvinfHashTableValueComparator);
return hTable;
return;
}
int32_t pos = UHASH_FIRST;
- const UHashElement* element = NULL;
+ const UHashElement* element = nullptr;
if ( source ) {
- while ( (element = source->nextElement(pos)) != NULL ) {
+ while ( (element = source->nextElement(pos)) != nullptr ) {
const UHashTok keyTok = element->key;
const UnicodeString* key = (UnicodeString*)keyTok.pointer;
const UHashTok valueTok = element->value;
const UnicodeString* value = (UnicodeString*)valueTok.pointer;
UnicodeString* copy = new UnicodeString[kIPI_MAX_INDEX];
+ if (copy == nullptr) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return;
+ }
int8_t i;
for ( i = 0; i < kIPI_MAX_INDEX; ++i ) {
copy[i] = value[i];