Skip to content

Commit 19ffd97

Browse files
author
Mel Dafert
committed
IntlDatePatternGenerator: coding style
1 parent f3a9e19 commit 19ffd97

File tree

3 files changed

+20
-35
lines changed

3 files changed

+20
-35
lines changed

ext/intl/dateformat/datepatterngenerator_class.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,13 @@ zend_object_handlers IntlDatePatternGenerator_handlers;
3636

3737
static zend_object *IntlDatePatternGenerator_object_clone(zend_object *object)
3838
{
39-
IntlDatePatternGenerator_object *dtpgo_orig,
40-
*dtpgo_new;
41-
zend_object *ret_val;
4239
intl_error_reset(NULL);
4340

44-
dtpgo_orig = php_intl_datepatterngenerator_fetch_object(object);
41+
IntlDatePatternGenerator_object *dtpgo_orig = php_intl_datepatterngenerator_fetch_object(object);
4542
intl_error_reset(DTPATTERNGEN_ERROR_P(dtpgo_orig));
4643

47-
ret_val = IntlDatePatternGenerator_ce_ptr->create_object(object->ce);
48-
dtpgo_new = php_intl_datepatterngenerator_fetch_object(ret_val);
44+
zend_object *ret_val = IntlDatePatternGenerator_ce_ptr->create_object(object->ce);
45+
IntlDatePatternGenerator_object *dtpgo_new = php_intl_datepatterngenerator_fetch_object(ret_val);
4946

5047
zend_objects_clone_members(&dtpgo_new->zo, &dtpgo_orig->zo);
5148

@@ -94,13 +91,13 @@ static void IntlDatePatternGenerator_object_free(zend_object *object)
9491

9592
static zend_object *IntlDatePatternGenerator_object_create(zend_class_entry *ce)
9693
{
97-
IntlDatePatternGenerator_object *intern = zend_object_alloc(sizeof(IntlDatePatternGenerator_object), ce);
94+
IntlDatePatternGenerator_object *intern =
95+
(IntlDatePatternGenerator_object*) zend_object_alloc(sizeof(IntlDatePatternGenerator_object), ce);
9896

9997
zend_object_std_init(&intern->zo, ce);
10098
object_properties_init(&intern->zo, ce);
10199
IntlDatePatternGenerator_object_init(intern);
102100

103-
104101
intern->zo.handlers = &IntlDatePatternGenerator_handlers;
105102

106103
return &intern->zo;

ext/intl/dateformat/datepatterngenerator_class.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#ifndef DATEPATTERNGENERATOR_CLASS_H
1616
#define DATEPATTERNGENERATOR_CLASS_H
1717

18-
//redefinition of inline in PHP headers causes problems, so include this before
19-
#include <math.h>
20-
2118
#include <php.h>
2219
#include "intl_common.h"
2320
#include "intl_error.h"
@@ -31,7 +28,7 @@ using icu::DateTimePatternGenerator;
3128

3229
typedef struct {
3330
// error handling
34-
intl_error err;
31+
intl_error err;
3532

3633
// ICU break iterator
3734
DateTimePatternGenerator *dtpg;
@@ -42,7 +39,7 @@ typedef struct {
4239
static inline IntlDatePatternGenerator_object *php_intl_datepatterngenerator_fetch_object(zend_object *obj) {
4340
return (IntlDatePatternGenerator_object *)((char*)(obj) - XtOffsetOf(IntlDatePatternGenerator_object, zo));
4441
}
45-
#define Z_INTL_DATETIMEPATTERNGENERATOR_P(zv) php_intl_datepatterngenerator_fetch_object(Z_OBJ_P(zv))
42+
#define Z_INTL_DATEPATTERNGENERATOR_P(zv) php_intl_datepatterngenerator_fetch_object(Z_OBJ_P(zv))
4643

4744
#define DTPATTERNGEN_ERROR(dtpgo) (dtpgo)->err
4845
#define DTPATTERNGEN_ERROR_P(dtpgo) &(DTPATTERNGEN_ERROR(dtpgo))
@@ -51,7 +48,7 @@ static inline IntlDatePatternGenerator_object *php_intl_datepatterngenerator_fet
5148
#define DTPATTERNGEN_ERROR_CODE_P(dtpgo) &(INTL_ERROR_CODE(DTPATTERNGEN_ERROR(dtpgo)))
5249

5350
#define DTPATTERNGEN_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlDatePatternGenerator, dtpgo)
54-
#define DTPATTERNGEN_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_DATETIMEPATTERNGENERATOR, dtpgo)
51+
#define DTPATTERNGEN_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_DATEPATTERNGENERATOR, dtpgo)
5552
#define DTPATTERNGEN_METHOD_FETCH_OBJECT \
5653
DTPATTERNGEN_METHOD_FETCH_OBJECT_NO_CHECK; \
5754
if (dtpgo->dtpg == NULL) \

ext/intl/dateformat/datepatterngenerator_methods.cpp

+12-21
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ using icu::StringPiece;
3232

3333
static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
3434
{
35-
zval *object;
36-
char *locale_str;
37-
size_t locale_len = 0;
38-
Locale locale;
35+
char *locale_str;
36+
size_t locale_len = 0;
3937
IntlDatePatternGenerator_object* dtpgo;
4038

4139
intl_error_reset(NULL);
42-
object = return_value;
40+
zval *object = return_value;
4341

4442
ZEND_PARSE_PARAMETERS_START(0, 1)
4543
Z_PARAM_OPTIONAL
@@ -57,7 +55,7 @@ static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
5755
if (locale_len == 0) {
5856
locale_str = (char *) intl_locale_get_default();
5957
}
60-
locale = Locale::createFromName(locale_str);
58+
Locale locale = Locale::createFromName(locale_str);
6159

6260
dtpgo->dtpg = DateTimePatternGenerator::createInstance(
6361
locale,
@@ -67,11 +65,10 @@ static zend_result dtpg_ctor(INTERNAL_FUNCTION_PARAMETERS)
6765
intl_error_set(NULL, DTPATTERNGEN_ERROR_CODE(dtpgo),
6866
"Error creating DateTimePatternGenerator",
6967
0);
70-
goto error;
68+
return FAILURE;
7169
}
7270

73-
error:
74-
return U_FAILURE(intl_error_get_code(NULL)) ? FAILURE : SUCCESS;
71+
return SUCCESS;
7572
}
7673

7774
U_CFUNC PHP_METHOD( IntlDatePatternGenerator, create )
@@ -107,7 +104,6 @@ U_CFUNC PHP_METHOD( IntlDatePatternGenerator, getBestPattern )
107104
char *skeleton_str = NULL;
108105
size_t skeleton_len;
109106
UnicodeString skeleton_uncleaned;
110-
UnicodeString skeleton;
111107

112108
DTPATTERNGEN_METHOD_INIT_VARS;
113109

@@ -124,22 +120,17 @@ U_CFUNC PHP_METHOD( IntlDatePatternGenerator, getBestPattern )
124120

125121
INTL_METHOD_CHECK_STATUS(dtpgo, "Skeleton is not a valid UTF-8 string");
126122

127-
skeleton = dtpgo->dtpg->getSkeleton(skeleton_uncleaned, DTPATTERNGEN_ERROR_CODE(dtpgo));
123+
UnicodeString skeleton = dtpgo->dtpg->getSkeleton(skeleton_uncleaned, DTPATTERNGEN_ERROR_CODE(dtpgo));
128124

129125
INTL_METHOD_CHECK_STATUS(dtpgo, "Error getting cleaned skeleton");
130126

131-
{
132-
zend_string *u8str;
133-
UnicodeString result;
134-
135-
result = dtpgo->dtpg->getBestPattern(skeleton, DTPATTERNGEN_ERROR_CODE(dtpgo));
127+
UnicodeString result = dtpgo->dtpg->getBestPattern(skeleton, DTPATTERNGEN_ERROR_CODE(dtpgo));
136128

137-
INTL_METHOD_CHECK_STATUS(dtpgo, "Error retrieving pattern");
129+
INTL_METHOD_CHECK_STATUS(dtpgo, "Error retrieving pattern");
138130

139-
u8str = intl_charFromString(result, DTPATTERNGEN_ERROR_CODE_P(dtpgo));
131+
zend_string *u8str = intl_charFromString(result, DTPATTERNGEN_ERROR_CODE_P(dtpgo));
140132

141-
INTL_METHOD_CHECK_STATUS(dtpgo, "Error converting result to UTF-8");
133+
INTL_METHOD_CHECK_STATUS(dtpgo, "Error converting result to UTF-8");
142134

143-
RETVAL_STR(u8str);
144-
}
135+
RETVAL_STR(u8str);
145136
}

0 commit comments

Comments
 (0)