Ver Fonte

Feat: Returns null if the type is specified and the cell is empty

viest há 5 anos atrás
pai
commit
f17ffead69
2 ficheiros alterados com 30 adições e 0 exclusões
  1. 1 0
      include/read.h
  2. 29 0
      kernel/read.c

+ 1 - 0
include/read.h

@@ -18,6 +18,7 @@
 
 int sheet_read_row(xlsxioreadersheet sheet_t);
 int is_number(const char *value);
+void data_to_null(zval *zv_result_t);
 void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_result_t);
 xlsxioreader file_open(const char *directory, const char *file_name);
 void load_sheet_all_data(xlsxioreadersheet sheet_t, zval *zv_type_t, zval *zv_result_t);

+ 29 - 0
kernel/read.c

@@ -52,6 +52,17 @@ int is_number(const char *value)
 }
 /* }}} */
 
+/* {{{ */
+void data_to_null(zval *zv_result_t)
+{
+    if (Z_TYPE_P(zv_result_t) == IS_ARRAY) {
+        add_next_index_null(zv_result_t);
+    } else {
+        ZVAL_NULL(zv_result_t);
+    }
+}
+/* }}} */
+
 /* {{{ */
 void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_result_t)
 {
@@ -60,6 +71,12 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
             goto STRING;
         }
 
+        if (strlen(string_value) == 0) {
+            data_to_null(zv_result_t);
+
+            return;
+        }
+
         double value = strtod(string_value, NULL);
 
         if (value != 0) {
@@ -80,6 +97,12 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
             goto STRING;
         }
 
+        if (strlen(string_value) == 0) {
+            data_to_null(zv_result_t);
+
+            return;
+        }
+
         if (Z_TYPE_P(zv_result_t) == IS_ARRAY) {
             add_next_index_double(zv_result_t, strtod(string_value, NULL));
         } else {
@@ -94,6 +117,12 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
             goto STRING;
         }
 
+        if (strlen(string_value) == 0) {
+            data_to_null(zv_result_t);
+
+            return;
+        }
+
         zend_long _long_value;
 
         sscanf(string_value, ZEND_LONG_FMT, &_long_value);