@@ -86,14 +86,16 @@ void data_to_null(zval *zv_result_t)
8686/* }}} */
8787
8888/* {{{ */
89- void data_to_custom_type (const char * string_value , zend_ulong type , zval * zv_result_t )
89+ void data_to_custom_type (const char * string_value , const zend_ulong type , zval * zv_result_t , const zend_ulong zv_hashtable_index )
9090{
91+ size_t string_value_length = strlen (string_value );
92+
9193 if (type & READ_TYPE_DATETIME ) {
9294 if (!is_number (string_value )) {
9395 goto STRING ;
9496 }
9597
96- if (strlen ( string_value ) == 0 ) {
98+ if (string_value_length == 0 ) {
9799 data_to_null (zv_result_t );
98100
99101 return ;
@@ -106,7 +108,7 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
106108 }
107109
108110 if (Z_TYPE_P (zv_result_t ) == IS_ARRAY ) {
109- add_next_index_long (zv_result_t , (zend_long )(value + 0.5 ));
111+ add_index_long (zv_result_t , zv_hashtable_index , (zend_long )(value + 0.5 ));
110112 } else {
111113 ZVAL_LONG (zv_result_t , (zend_long )(value + 0.5 ));
112114 }
@@ -119,14 +121,14 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
119121 goto STRING ;
120122 }
121123
122- if (strlen ( string_value ) == 0 ) {
124+ if (string_value_length == 0 ) {
123125 data_to_null (zv_result_t );
124126
125127 return ;
126128 }
127129
128130 if (Z_TYPE_P (zv_result_t ) == IS_ARRAY ) {
129- add_next_index_double (zv_result_t , strtod (string_value , NULL ));
131+ add_index_double (zv_result_t , zv_hashtable_index , strtod (string_value , NULL ));
130132 } else {
131133 ZVAL_DOUBLE (zv_result_t , strtod (string_value , NULL ));
132134 }
@@ -139,7 +141,7 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
139141 goto STRING ;
140142 }
141143
142- if (strlen ( string_value ) == 0 ) {
144+ if (string_value_length == 0 ) {
143145 data_to_null (zv_result_t );
144146
145147 return ;
@@ -150,7 +152,7 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
150152 sscanf (string_value , ZEND_LONG_FMT , & _long_value );
151153
152154 if (Z_TYPE_P (zv_result_t ) == IS_ARRAY ) {
153- add_next_index_long (zv_result_t , _long_value );
155+ add_index_long (zv_result_t , zv_hashtable_index , _long_value );
154156 } else {
155157 ZVAL_LONG (zv_result_t , _long_value );
156158 }
@@ -164,19 +166,19 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
164166 zend_long _long = 0 ; double _double = 0 ;
165167
166168 if (!(type & READ_TYPE_STRING )) {
167- is_numeric_string (string_value , strlen ( string_value ) , & _long , & _double , 0 );
169+ is_numeric_string (string_value , string_value_length , & _long , & _double , 0 );
168170 }
169171
170172 if (Z_TYPE_P (zv_result_t ) == IS_ARRAY ) {
171173 if (_double > 0 ) {
172- add_next_index_double (zv_result_t , _double );
174+ add_index_double (zv_result_t , zv_hashtable_index , _double );
173175 return ;
174176 } else if (_long > 0 ) {
175- add_next_index_long (zv_result_t , _long );
177+ add_index_long (zv_result_t , zv_hashtable_index , _long );
176178 return ;
177179 }
178180
179- add_next_index_stringl (zv_result_t , string_value , strlen ( string_value ) );
181+ add_index_stringl (zv_result_t , zv_hashtable_index , string_value , string_value_length );
180182 return ;
181183 }
182184
@@ -188,7 +190,7 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
188190 return ;
189191 }
190192
191- ZVAL_STRINGL (zv_result_t , string_value , strlen ( string_value ) );
193+ ZVAL_STRINGL (zv_result_t , string_value , string_value_length );
192194 }
193195}
194196/* }}} */
@@ -203,7 +205,8 @@ int sheet_read_row(xlsxioreadersheet sheet_t)
203205/* {{{ */
204206unsigned int load_sheet_current_row_data (xlsxioreadersheet sheet_t , zval * zv_result_t , zval * zv_type_arr_t , unsigned int flag )
205207{
206- zend_ulong _type , _cell_index = 0 ;
208+ zend_long _type , _cell_index = 0 , _last_cell_index = 0 ;
209+ zend_bool _skip_empty_value_cell = 0 ;
207210 zend_array * _za_type_t = NULL ;
208211 char * _string_value = NULL ;
209212 zval * _current_type = NULL ;
@@ -212,6 +215,10 @@ unsigned int load_sheet_current_row_data(xlsxioreadersheet sheet_t, zval *zv_res
212215 return XLSWRITER_FALSE ;
213216 }
214217
218+ if (xlsxioread_sheet_flags (sheet_t ) & SKIP_EMPTY_VALUE ) {
219+ _skip_empty_value_cell = 1 ;
220+ }
221+
215222 if (Z_TYPE_P (zv_result_t ) != IS_ARRAY ) {
216223 array_init (zv_result_t );
217224 }
@@ -223,19 +230,33 @@ unsigned int load_sheet_current_row_data(xlsxioreadersheet sheet_t, zval *zv_res
223230 while ((_string_value = xlsxioread_sheet_next_cell (sheet_t )) != NULL )
224231 {
225232 _type = READ_TYPE_EMPTY ;
233+ _last_cell_index = xlsxioread_sheet_last_column_index (sheet_t ) - 1 ;
234+
235+ if (_last_cell_index < 0 ) {
236+ goto FREE_TMP_VALUE ;
237+ }
238+
239+ if (_skip_empty_value_cell && strlen (_string_value ) == 0 ) {
240+ goto FREE_TMP_VALUE ;
241+ }
242+
243+ if (_last_cell_index > _cell_index ) {
244+ _cell_index = _last_cell_index ;
245+ }
226246
227247 if (_za_type_t != NULL ) {
228248 if ((_current_type = zend_hash_index_find (_za_type_t , _cell_index )) != NULL ) {
229249 if (Z_TYPE_P (_current_type ) == IS_LONG ) {
230250 _type = Z_LVAL_P (_current_type );
231251 }
232252 }
233-
234- _cell_index ++ ;
235253 }
236254
237- data_to_custom_type (_string_value , _type , zv_result_t );
255+ data_to_custom_type (_string_value , _type , zv_result_t , _cell_index );
256+
257+ FREE_TMP_VALUE :
238258
259+ _cell_index ++ ;
239260 free (_string_value );
240261 }
241262
@@ -322,7 +343,7 @@ int sheet_cell_callback (size_t row, size_t col, const char *value, void *callba
322343 }
323344 }
324345
325- data_to_custom_type (value , _type , & args [2 ]);
346+ data_to_custom_type (value , _type , & args [2 ], 0 );
326347 }
327348
328349 CALL_USER_FUNCTION :
@@ -337,7 +358,7 @@ int sheet_cell_callback (size_t row, size_t col, const char *value, void *callba
337358/* }}} */
338359
339360/* {{{ */
340- unsigned int load_sheet_current_row_data_callback (zend_string * zs_sheet_name_t , xlsxioreader file_t , void * callback_data )
361+ unsigned int load_sheet_current_row_data_callback (zend_string * zs_sheet_name_t , xlsxioreader file_t , void * callback_data )
341362{
342363 if (zs_sheet_name_t == NULL ) {
343364 return xlsxioread_process (file_t , NULL , XLSXIOREAD_SKIP_NONE , sheet_cell_callback , sheet_row_callback , callback_data );
@@ -348,7 +369,7 @@ unsigned int load_sheet_current_row_data_callback(zend_string *zs_sheet_name_t,
348369/* }}} */
349370
350371/* {{{ */
351- void load_sheet_all_data (xlsxioreadersheet sheet_t , zval * zv_type_t , zval * zv_result_t )
372+ void load_sheet_all_data (xlsxioreadersheet sheet_t , zval * zv_type_t , zval * zv_result_t )
352373{
353374 if (Z_TYPE_P (zv_result_t ) != IS_ARRAY ) {
354375 array_init (zv_result_t );
0 commit comments