@@ -70,10 +70,10 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
70
70
size_t locale_len;
71
71
bool pattern = false ;
72
72
UDate date;
73
- TimeZone * timeZone = NULL ;
73
+ std::unique_ptr< TimeZone> timeZone;
74
74
UErrorCode status = U_ZERO_ERROR;
75
- DateFormat *df = NULL ;
76
- Calendar *cal = NULL ;
75
+ std::unique_ptr< DateFormat> df ;
76
+ std::unique_ptr< Calendar> cal ;
77
77
DateFormat::EStyle dateStyle = DateFormat::kDefault ,
78
78
timeStyle = DateFormat::kDefault ;
79
79
@@ -158,28 +158,28 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
158
158
" not initialized properly" , 0 );
159
159
RETURN_FALSE;
160
160
}
161
- timeZone = obj_cal->getTimeZone ().clone ();
161
+ timeZone = std::unique_ptr<TimeZone>( obj_cal->getTimeZone ().clone () );
162
162
date = obj_cal->getTime (status);
163
163
if (U_FAILURE (status)) {
164
164
intl_error_set (NULL , status,
165
165
" datefmt_format_object: error obtaining instant from "
166
166
" IntlCalendar" , 0 );
167
- RETVAL_FALSE;
168
- goto cleanup;
167
+ RETURN_FALSE;
169
168
}
170
- cal = obj_cal->clone ();
169
+ cal = std::unique_ptr<Calendar>( obj_cal->clone () );
171
170
} else if (instanceof_function (instance_ce, php_date_get_interface_ce ())) {
172
- if (intl_datetime_decompose (object, &date, &timeZone, NULL ,
171
+ TimeZone *tz;
172
+ if (intl_datetime_decompose (object, &date, &tz, NULL ,
173
173
" datefmt_format_object" ) == FAILURE) {
174
174
RETURN_FALSE;
175
175
}
176
- cal = new GregorianCalendar (Locale::createFromName (locale_str), status);
176
+ timeZone = std::unique_ptr<TimeZone>(tz);
177
+ cal = std::unique_ptr<Calendar>(new GregorianCalendar (Locale::createFromName (locale_str), status));
177
178
if (U_FAILURE (status)) {
178
179
intl_error_set (NULL , status,
179
180
" datefmt_format_object: could not create GregorianCalendar" ,
180
181
0 );
181
- RETVAL_FALSE;
182
- goto cleanup;
182
+ RETURN_FALSE;
183
183
}
184
184
} else {
185
185
intl_error_set (NULL , status, " datefmt_format_object: the passed object "
@@ -190,36 +190,32 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
190
190
191
191
if (pattern) {
192
192
StringPiece sp (Z_STRVAL_P (format));
193
- df = new SimpleDateFormat (
193
+ df = std::unique_ptr<DateFormat>( new SimpleDateFormat (
194
194
UnicodeString::fromUTF8 (sp),
195
195
Locale::createFromName (locale_str),
196
- status);
196
+ status)) ;
197
197
198
198
if (U_FAILURE (status)) {
199
199
intl_error_set (NULL , status,
200
200
" datefmt_format_object: could not create SimpleDateFormat" ,
201
201
0 );
202
- RETVAL_FALSE;
203
- goto cleanup;
202
+ RETURN_FALSE;
204
203
}
205
204
} else {
206
- df = DateFormat::createDateTimeInstance (dateStyle, timeStyle,
207
- Locale::createFromName (locale_str));
205
+ df = std::unique_ptr<DateFormat>( DateFormat::createDateTimeInstance (dateStyle, timeStyle,
206
+ Locale::createFromName (locale_str))) ;
208
207
209
208
if (df == NULL ) { /* according to ICU sources, this should never happen */
210
209
intl_error_set (NULL , status,
211
210
" datefmt_format_object: could not create DateFormat" ,
212
211
0 );
213
- RETVAL_FALSE;
214
- goto cleanup;
212
+ RETURN_FALSE;
215
213
}
216
214
}
217
215
218
216
// must be in this order (or have the cal adopt the tz)
219
- df->adoptCalendar (cal);
220
- cal = NULL ;
221
- df->adoptTimeZone (timeZone);
222
- timeZone = NULL ;
217
+ df->adoptCalendar (cal.release ());
218
+ df->adoptTimeZone (timeZone.release ());
223
219
224
220
{
225
221
zend_string *u8str;
@@ -231,15 +227,8 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
231
227
intl_error_set (NULL , status,
232
228
" datefmt_format_object: error converting result to UTF-8" ,
233
229
0 );
234
- RETVAL_FALSE;
235
- goto cleanup;
230
+ RETURN_FALSE;
236
231
}
237
232
RETVAL_STR (u8str);
238
233
}
239
-
240
-
241
- cleanup:
242
- delete df;
243
- delete timeZone;
244
- delete cal;
245
234
}
0 commit comments