File tree 2 files changed +16
-10
lines changed
2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -273,22 +273,25 @@ class Reader {
273
273
/* *
274
274
* @returns The number of rows (excluding the header)
275
275
*/
276
- size_t rows () const {
276
+ size_t rows (bool ignore_empty_lines = false ) const {
277
277
size_t result{0 };
278
278
if (!buffer_ || buffer_size_ == 0 )
279
279
return result;
280
280
281
281
// Count the first row if not header
282
282
if (not first_row_is_header::value
283
- and *(static_cast <const char *>(buffer_)) != ' \r ' )
283
+ and (not ignore_empty_lines
284
+ or *(static_cast <const char *>(buffer_)) != ' \r ' ))
284
285
++result;
285
286
286
287
for (const char *p = buffer_
287
288
; (p = static_cast <const char *>(memchr (p, ' \n ' , (buffer_ + buffer_size_) - p)))
288
289
; ++p) {
289
- if (p < buffer_ + buffer_size_ - 1
290
- and *(p + 1 ) != ' \r ' )
291
- ++result;
290
+ if (ignore_empty_lines
291
+ and (p >= buffer_ + buffer_size_ - 1
292
+ or *(p + 1 ) == ' \r ' ))
293
+ continue ;
294
+ ++result;
292
295
}
293
296
return result;
294
297
}
Original file line number Diff line number Diff line change @@ -1904,22 +1904,25 @@ class Reader {
1904
1904
/* *
1905
1905
* @returns The number of rows (excluding the header)
1906
1906
*/
1907
- size_t rows () const {
1907
+ size_t rows (bool ignore_empty_lines = false ) const {
1908
1908
size_t result{0 };
1909
1909
if (!buffer_ || buffer_size_ == 0 )
1910
1910
return result;
1911
1911
1912
1912
// Count the first row if not header
1913
1913
if (not first_row_is_header::value
1914
- and *(static_cast <const char *>(buffer_)) != ' \r ' )
1914
+ and (not ignore_empty_lines
1915
+ or *(static_cast <const char *>(buffer_)) != ' \r ' ))
1915
1916
++result;
1916
1917
1917
1918
for (const char *p = buffer_
1918
1919
; (p = static_cast <const char *>(memchr (p, ' \n ' , (buffer_ + buffer_size_) - p)))
1919
1920
; ++p) {
1920
- if (p < buffer_ + buffer_size_ - 1
1921
- and *(p + 1 ) != ' \r ' )
1922
- ++result;
1921
+ if (ignore_empty_lines
1922
+ and (p >= buffer_ + buffer_size_ - 1
1923
+ or *(p + 1 ) == ' \r ' ))
1924
+ continue ;
1925
+ ++result;
1923
1926
}
1924
1927
return result;
1925
1928
}
You can’t perform that action at this time.
0 commit comments