mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
ext/soap: Refactor to_zval_bool() (#18696)
- Early return style - Improve logic to get rid of unnecessary comparisons - Do not use convert_to_boolean API
This commit is contained in:
parent
407c9781f9
commit
c9e571560f
1 changed files with 18 additions and 20 deletions
|
@ -1118,29 +1118,27 @@ static xmlNodePtr to_xml_double(encodeTypePtr type, zval *data, int style, xmlNo
|
|||
|
||||
static zval *to_zval_bool(zval *ret, encodeTypePtr type, xmlNodePtr data)
|
||||
{
|
||||
ZVAL_NULL(ret);
|
||||
FIND_XML_NULL(data, ret);
|
||||
|
||||
if (data && data->children) {
|
||||
if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) {
|
||||
whiteSpace_collapse(data->children->content);
|
||||
if (stricmp((char*)data->children->content, "true") == 0 ||
|
||||
stricmp((char*)data->children->content, "t") == 0 ||
|
||||
strcmp((char*)data->children->content, "1") == 0) {
|
||||
ZVAL_TRUE(ret);
|
||||
} else if (stricmp((char*)data->children->content, "false") == 0 ||
|
||||
stricmp((char*)data->children->content, "f") == 0 ||
|
||||
strcmp((char*)data->children->content, "0") == 0) {
|
||||
ZVAL_FALSE(ret);
|
||||
} else {
|
||||
ZVAL_STRING(ret, (char*)data->children->content);
|
||||
convert_to_boolean(ret);
|
||||
if (!data->children) {
|
||||
ZVAL_NULL(ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
if (data->children->type != XML_TEXT_NODE || data->children->next != NULL) {
|
||||
// TODO Convert to exception?
|
||||
soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
|
||||
}
|
||||
|
||||
whiteSpace_collapse(data->children->content);
|
||||
if (
|
||||
data->children->content[0] == '\0' /* Check for empty string */
|
||||
|| strcmp((const char*)data->children->content, "0") == 0
|
||||
|| stricmp((const char*)data->children->content, "f") == 0
|
||||
|| stricmp((const char*)data->children->content, "false") == 0
|
||||
) {
|
||||
ZVAL_FALSE(ret);
|
||||
} else {
|
||||
ZVAL_NULL(ret);
|
||||
ZVAL_TRUE(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue