mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Use some early returns in spl_directory
This commit is contained in:
parent
a3abcc063e
commit
1a81251dbb
1 changed files with 51 additions and 52 deletions
|
@ -1900,27 +1900,26 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent) /
|
||||||
|
|
||||||
static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char delimiter, char enclosure, int escape, zval *return_value) /* {{{ */
|
static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char delimiter, char enclosure, int escape, zval *return_value) /* {{{ */
|
||||||
{
|
{
|
||||||
int ret = SUCCESS;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = spl_filesystem_file_read(intern, 1);
|
int ret = spl_filesystem_file_read(intern, 1);
|
||||||
} while (ret == SUCCESS && !intern->u.file.current_line_len && SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY));
|
if (ret != SUCCESS) {
|
||||||
|
return ret;
|
||||||
if (ret == SUCCESS) {
|
|
||||||
size_t buf_len = intern->u.file.current_line_len;
|
|
||||||
char *buf = estrndup(intern->u.file.current_line, buf_len);
|
|
||||||
|
|
||||||
if (!Z_ISUNDEF(intern->u.file.current_zval)) {
|
|
||||||
zval_ptr_dtor(&intern->u.file.current_zval);
|
|
||||||
ZVAL_UNDEF(&intern->u.file.current_zval);
|
|
||||||
}
|
}
|
||||||
|
} while (!intern->u.file.current_line_len && SPL_HAS_FLAG(intern->flags, SPL_FILE_OBJECT_SKIP_EMPTY));
|
||||||
|
|
||||||
php_fgetcsv(intern->u.file.stream, delimiter, enclosure, escape, buf_len, buf, &intern->u.file.current_zval);
|
size_t buf_len = intern->u.file.current_line_len;
|
||||||
if (return_value) {
|
char *buf = estrndup(intern->u.file.current_line, buf_len);
|
||||||
ZVAL_COPY(return_value, &intern->u.file.current_zval);
|
|
||||||
}
|
if (!Z_ISUNDEF(intern->u.file.current_zval)) {
|
||||||
|
zval_ptr_dtor(&intern->u.file.current_zval);
|
||||||
|
ZVAL_UNDEF(&intern->u.file.current_zval);
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
|
php_fgetcsv(intern->u.file.stream, delimiter, enclosure, escape, buf_len, buf, &intern->u.file.current_zval);
|
||||||
|
if (return_value) {
|
||||||
|
ZVAL_COPY(return_value, &intern->u.file.current_zval);
|
||||||
|
}
|
||||||
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -2300,42 +2299,42 @@ PHP_METHOD(SplFileObject, fgetcsv)
|
||||||
char *delim = NULL, *enclo = NULL, *esc = NULL;
|
char *delim = NULL, *enclo = NULL, *esc = NULL;
|
||||||
size_t d_len = 0, e_len = 0, esc_len = 0;
|
size_t d_len = 0, e_len = 0, esc_len = 0;
|
||||||
|
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == SUCCESS) {
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &delim, &d_len, &enclo, &e_len, &esc, &esc_len) == FAILURE) {
|
||||||
|
RETURN_THROWS();
|
||||||
CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);
|
|
||||||
|
|
||||||
switch(ZEND_NUM_ARGS())
|
|
||||||
{
|
|
||||||
case 3:
|
|
||||||
if (esc_len > 1) {
|
|
||||||
zend_argument_value_error(3, "must be empty or a single character");
|
|
||||||
RETURN_THROWS();
|
|
||||||
}
|
|
||||||
if (esc_len == 0) {
|
|
||||||
escape = PHP_CSV_NO_ESCAPE;
|
|
||||||
} else {
|
|
||||||
escape = (unsigned char) esc[0];
|
|
||||||
}
|
|
||||||
ZEND_FALLTHROUGH;
|
|
||||||
case 2:
|
|
||||||
if (e_len != 1) {
|
|
||||||
zend_argument_value_error(2, "must be a single character");
|
|
||||||
RETURN_THROWS();
|
|
||||||
}
|
|
||||||
enclosure = enclo[0];
|
|
||||||
ZEND_FALLTHROUGH;
|
|
||||||
case 1:
|
|
||||||
if (d_len != 1) {
|
|
||||||
zend_argument_value_error(1, "must be a single character");
|
|
||||||
RETURN_THROWS();
|
|
||||||
}
|
|
||||||
delimiter = delim[0];
|
|
||||||
ZEND_FALLTHROUGH;
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern);
|
||||||
|
|
||||||
|
switch (ZEND_NUM_ARGS()) {
|
||||||
|
case 3:
|
||||||
|
if (esc_len > 1) {
|
||||||
|
zend_argument_value_error(3, "must be empty or a single character");
|
||||||
|
RETURN_THROWS();
|
||||||
|
}
|
||||||
|
if (esc_len == 0) {
|
||||||
|
escape = PHP_CSV_NO_ESCAPE;
|
||||||
|
} else {
|
||||||
|
escape = (unsigned char) esc[0];
|
||||||
|
}
|
||||||
|
ZEND_FALLTHROUGH;
|
||||||
|
case 2:
|
||||||
|
if (e_len != 1) {
|
||||||
|
zend_argument_value_error(2, "must be a single character");
|
||||||
|
RETURN_THROWS();
|
||||||
|
}
|
||||||
|
enclosure = enclo[0];
|
||||||
|
ZEND_FALLTHROUGH;
|
||||||
|
case 1:
|
||||||
|
if (d_len != 1) {
|
||||||
|
zend_argument_value_error(1, "must be a single character");
|
||||||
|
RETURN_THROWS();
|
||||||
|
}
|
||||||
|
delimiter = delim[0];
|
||||||
|
ZEND_FALLTHROUGH;
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
spl_filesystem_file_read_csv(intern, delimiter, enclosure, escape, return_value);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue