Parse CSV Cells */
| 80 | |
| 81 | /* Parse CSV Cells */ |
| 82 | hb_csv_cell_t *hb_read_next_cell( hb_csv_file_t *file ) |
| 83 | { |
| 84 | hb_csv_cell_t *cell = NULL; |
| 85 | uint16_t c; |
| 86 | int index; |
| 87 | |
| 88 | if( file == NULL ) |
| 89 | { |
| 90 | return cell; |
| 91 | } |
| 92 | |
| 93 | if( file->eof ) |
| 94 | { |
| 95 | return cell; |
| 96 | } |
| 97 | |
| 98 | cell = malloc( sizeof( hb_csv_cell_t ) ); |
| 99 | if( cell == NULL ) |
| 100 | { |
| 101 | return cell; |
| 102 | } |
| 103 | |
| 104 | cell->cell_row = file->curr_row; |
| 105 | cell->cell_col = file->curr_col; |
| 106 | index = 0; |
| 107 | while( CSV_CHAR_EOF != (c = hb_parse_character( file ) ) ) |
| 108 | { |
| 109 | if( c == CSV_CHAR_ROWSEP ) |
| 110 | { |
| 111 | file->curr_row++; |
| 112 | file->curr_col = 0; |
| 113 | break; |
| 114 | } |
| 115 | else if( c == CSV_CHAR_COLSEP ) |
| 116 | { |
| 117 | file->curr_col++; |
| 118 | break; |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | if( index < 1023 ) |
| 123 | { |
| 124 | cell->cell_text[index] = (char)c; |
| 125 | index++; |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if( c == CSV_CHAR_EOF ) |
| 131 | { |
| 132 | file->eof = 1; |
| 133 | } |
| 134 | |
| 135 | /* Terminate the cell text */ |
| 136 | cell->cell_text[index] = '\0'; |
| 137 | hb_trim_end( cell->cell_text ); |
| 138 | return cell; |
| 139 | } |