@@ -324,6 +324,7 @@ static mp_obj_t io_loadtxt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
324324 char * offset ;
325325 uint16_t rows = 0 , items = 0 , all_rows = 0 ;
326326 uint8_t read ;
327+ uint8_t len = 0 ;
327328
328329 do {
329330 read = (uint8_t )stream_p -> read (stream , buffer , ULAB_IO_BUFFER_SIZE - 1 , & error );
@@ -347,6 +348,7 @@ static mp_obj_t io_loadtxt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
347348 rows ++ ;
348349 all_rows ++ ;
349350 items ++ ;
351+ len = 0 ;
350352 if (all_rows == max_rows ) {
351353 break ;
352354 }
@@ -358,9 +360,13 @@ static mp_obj_t io_loadtxt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
358360 while ((* offset == ' ' ) || (* offset == '\t' ) || (* offset == '\v' ) || (* offset == '\f' ) || (* offset == '\r' )) {
359361 offset ++ ;
360362 }
361- items ++ ;
363+ if (len > 0 ) {
364+ items ++ ;
365+ len = 0 ;
366+ }
362367 } else {
363368 offset ++ ;
369+ len ++ ;
364370 }
365371 }
366372 } while ((read > 0 ) && (all_rows < max_rows ));
@@ -394,10 +400,10 @@ static mp_obj_t io_loadtxt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
394400
395401 char * clipboard = m_new (char , ULAB_IO_CLIPBOARD_SIZE );
396402 char * clipboard_origin = clipboard ;
397- uint8_t len = 0 ;
398403
399404 rows = 0 ;
400405 columns = 0 ;
406+ len = 0 ;
401407
402408 size_t idx = 0 ;
403409 do {
@@ -421,34 +427,37 @@ static mp_obj_t io_loadtxt(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
421427 if ((* offset == ' ' ) || (* offset == '\t' ) || (* offset == '\v' ) ||
422428 (* offset == '\f' ) || (* offset == '\r' ) || (* offset == '\n' ) || (* offset == delimiter )) {
423429 offset ++ ;
424- while ((* offset == ' ' ) || (* offset == '\t' ) || (* offset == '\v' ) || (* offset == '\f' ) || (* offset == '\r' ) || (* offset == '\n' )) {
430+ while ((* offset == ' ' ) || (* offset == '\t' ) || (* offset == '\v' ) ||
431+ (* offset == '\f' ) || (* offset == '\r' ) || (* offset == '\n' )) {
425432 offset ++ ;
426433 }
427- clipboard = clipboard_origin ;
428- #if ULAB_MAX_DIMS == 1
429- if (columns == cols [0 ]) {
430- io_assign_value (clipboard , len , ndarray , & idx , dtype );
431- }
432- #else
433- if (args [4 ].u_obj == mp_const_none ) {
434- io_assign_value (clipboard , len , ndarray , & idx , dtype );
435- } else {
436- for (uint8_t c = 0 ; c < used_columns ; c ++ ) {
437- if (columns == cols [c ]) {
438- io_assign_value (clipboard , len , ndarray , & idx , dtype );
439- break ;
434+ if (len > 0 ) {
435+ clipboard = clipboard_origin ;
436+ #if ULAB_MAX_DIMS == 1
437+ if (columns == cols [0 ]) {
438+ io_assign_value (clipboard , len , ndarray , & idx , dtype );
439+ }
440+ #else
441+ if (args [4 ].u_obj == mp_const_none ) {
442+ io_assign_value (clipboard , len , ndarray , & idx , dtype );
443+ } else {
444+ for (uint8_t c = 0 ; c < used_columns ; c ++ ) {
445+ if (columns == cols [c ]) {
446+ io_assign_value (clipboard , len , ndarray , & idx , dtype );
447+ break ;
448+ }
440449 }
441450 }
442- }
443- #endif
444- columns ++ ;
445- len = 0 ;
451+ #endif
452+ columns ++ ;
453+ len = 0 ;
446454
447- if (offset [-1 ] == '\n' ) {
448- columns = 0 ;
449- rows ++ ;
450- if (rows == max_rows ) {
451- break ;
455+ if (offset [-1 ] == '\n' ) {
456+ columns = 0 ;
457+ rows ++ ;
458+ if (rows == max_rows ) {
459+ break ;
460+ }
452461 }
453462 }
454463 } else {
0 commit comments