Skip to content

Commit

Permalink
fix zsv_cum_scanned_length bug if called during final() when input ha…
Browse files Browse the repository at this point in the history
…s no trailing line end (#184)

add zsv_row_length_raw_bytes()
  • Loading branch information
liquidaty authored Aug 2, 2024
1 parent c069e3f commit 6950d93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/zsv/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ ZSV_EXPORT size_t zsv_scanned_length(zsv_parser);
*/
ZSV_EXPORT size_t zsv_cum_scanned_length(zsv_parser parser);

/**
* @return number of raw bytes scanned from the beginning to the end of this row
*/
ZSV_EXPORT size_t zsv_row_length_raw_bytes(zsv_parser parser);

/**
* Check the quoted status of the last cell that was read. This function is only
* applicable when called from within a cell_handler() callback. Furthermore, this
Expand Down
9 changes: 8 additions & 1 deletion src/zsv.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,14 @@ size_t zsv_scanned_length(zsv_parser parser) {

ZSV_EXPORT
size_t zsv_cum_scanned_length(zsv_parser parser) {
return parser->cum_scanned_length + parser->scanned_length + (parser->had_bom ? strlen(ZSV_BOM) : 0);
return parser->cum_scanned_length +
(parser->finished ? 0 : parser->scanned_length) +
(parser->had_bom ? strlen(ZSV_BOM) : 0);
}

ZSV_EXPORT
size_t zsv_row_length_raw_bytes(zsv_parser parser) {
return parser->scanned_length - parser->row_start;
}

/**
Expand Down

0 comments on commit 6950d93

Please sign in to comment.