Skip to content

Commit aadd724

Browse files
authored
ext/intl: Refactor IntlRuleBasedBreakIterator::__construct() (#19164)
There is no need to delegate this to a seperate function and overwrite the error handler to promote warnings
1 parent 6b3f302 commit aadd724

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) {
3232
return (RuleBasedBreakIterator*)bio->biter;
3333
}
3434

35-
static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_error_handling *error_handling, bool *error_handling_replaced)
35+
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
3636
{
37-
char *rules;
38-
size_t rules_len;
39-
bool compiled = false;
40-
UErrorCode status = U_ZERO_ERROR;
37+
zend_string *rules;
38+
bool compiled = false;
39+
UErrorCode status = U_ZERO_ERROR;
4140
BREAKITER_METHOD_INIT_VARS;
4241
object = ZEND_THIS;
4342

4443
ZEND_PARSE_PARAMETERS_START(1, 2)
45-
Z_PARAM_STRING(rules, rules_len)
44+
Z_PARAM_STR(rules)
4645
Z_PARAM_OPTIONAL
4746
Z_PARAM_BOOL(compiled)
4847
ZEND_PARSE_PARAMETERS_END();
@@ -53,20 +52,14 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_er
5352
RETURN_THROWS();
5453
}
5554

56-
zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, error_handling);
57-
*error_handling_replaced = 1;
58-
59-
// instantiation of ICU object
6055
RuleBasedBreakIterator *rbbi;
6156

6257
if (!compiled) {
6358
UnicodeString rulesStr;
6459
UParseError parseError = UParseError();
65-
if (intl_stringFromChar(rulesStr, rules, rules_len, &status)
66-
== FAILURE) {
60+
if (intl_stringFromChar(rulesStr, ZSTR_VAL(rules), ZSTR_LEN(rules), &status) == FAILURE) {
6761
zend_throw_exception(IntlException_ce_ptr,
68-
"IntlRuleBasedBreakIterator::__construct(): "
69-
"rules were not a valid UTF-8 string", 0);
62+
"IntlRuleBasedBreakIterator::__construct(): rules were not a valid UTF-8 string", 0);
7063
RETURN_THROWS();
7164
}
7265

@@ -84,29 +77,16 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_er
8477
RETURN_THROWS();
8578
}
8679
} else { // compiled
87-
rbbi = new RuleBasedBreakIterator((uint8_t*)rules, rules_len, status);
80+
rbbi = new RuleBasedBreakIterator(reinterpret_cast<uint8_t *>(ZSTR_VAL(rules)), ZSTR_LEN(rules), status);
8881
if (U_FAILURE(status)) {
8982
zend_throw_exception(IntlException_ce_ptr,
90-
"IntlRuleBasedBreakIterator::__construct(): "
91-
"unable to create instance from compiled rules", 0);
83+
"IntlRuleBasedBreakIterator::__construct(): unable to create instance from compiled rules", 0);
9284
delete rbbi;
9385
RETURN_THROWS();
9486
}
9587
}
9688

97-
breakiterator_object_create(return_value, rbbi, 0);
98-
}
99-
100-
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
101-
{
102-
zend_error_handling error_handling;
103-
bool error_handling_replaced = 0;
104-
105-
return_value = ZEND_THIS;
106-
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, &error_handling, &error_handling_replaced);
107-
if (error_handling_replaced) {
108-
zend_restore_error_handling(&error_handling);
109-
}
89+
breakiterator_object_create(object, rbbi, false);
11090
}
11191

11292
U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, getRules)

0 commit comments

Comments
 (0)