Mercurial > octave
comparison libinterp/corefcn/oct-stream.cc @ 28183:abcff237241f
Fix textscan handling of empty fields at end of line (Bug #57612).
* oct-stream.cc (skip_whitespace): Change function prototype to have second
argument, EOLstop, default to true.
* oct-stream.cc (textscan_format_list::read_first_row): Add 2nd argument of
false to call to skip_whitespace to reproduce old behavior.
* oct-stream.cc (textscan::skip_delim): Delete unnecessary second argument
of true to skip_whitespace(). Adjust comments for code.
* file-io.cc (Ftextscan): Comment out BIST test for handling of precision which
is already incompatibile with Matlab. Add 3 new BIST tests for bug #57612.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 29 Mar 2020 11:26:16 -0700 |
parents | 56349d9ca566 |
children | 83172e1c77f2 |
comparison
equal
deleted
inserted
replaced
28182:56349d9ca566 | 28183:abcff237241f |
---|---|
1912 int lookahead (delimited_stream& is, const Cell& targets, int max_len, | 1912 int lookahead (delimited_stream& is, const Cell& targets, int max_len, |
1913 bool case_sensitive = true) const; | 1913 bool case_sensitive = true) const; |
1914 | 1914 |
1915 bool match_literal (delimited_stream& isp, const textscan_format_elt& elem); | 1915 bool match_literal (delimited_stream& isp, const textscan_format_elt& elem); |
1916 | 1916 |
1917 int skip_whitespace (delimited_stream& is, bool EOLstop = false); | 1917 int skip_whitespace (delimited_stream& is, bool EOLstop = true); |
1918 | 1918 |
1919 int skip_delim (delimited_stream& is); | 1919 int skip_delim (delimited_stream& is); |
1920 | 1920 |
1921 bool is_delim (unsigned char ch) const | 1921 bool is_delim (unsigned char ch) const |
1922 { | 1922 { |
2470 | 2470 |
2471 // read line, creating output_container as we go | 2471 // read line, creating output_container as we go |
2472 while (! ds.eof ()) | 2472 while (! ds.eof ()) |
2473 { | 2473 { |
2474 bool already_skipped_delim = false; | 2474 bool already_skipped_delim = false; |
2475 ts.skip_whitespace (ds); | 2475 ts.skip_whitespace (ds, false); |
2476 ds.progress_benchmark (); | 2476 ds.progress_benchmark (); |
2477 ts.scan_complex (ds, *fmt_elts[0], val); | 2477 ts.scan_complex (ds, *fmt_elts[0], val); |
2478 if (ds.fail ()) | 2478 if (ds.fail ()) |
2479 { | 2479 { |
2480 ds.clear (ds.rdstate () & ~std::ios::failbit); | 2480 ds.clear (ds.rdstate () & ~std::ios::failbit); |
3891 | 3891 |
3892 // Skip delimiters -- multiple if MultipleDelimsAsOne specified. | 3892 // Skip delimiters -- multiple if MultipleDelimsAsOne specified. |
3893 int | 3893 int |
3894 textscan::skip_delim (delimited_stream& is) | 3894 textscan::skip_delim (delimited_stream& is) |
3895 { | 3895 { |
3896 int c1 = skip_whitespace (is, true); // 'true': stop once EOL is read | 3896 int c1 = skip_whitespace (is); // Stop once EOL is read |
3897 if (delim_list.numel () == 0) // single character delimiter | 3897 if (delim_list.numel () == 0) // single character delimiter |
3898 { | 3898 { |
3899 if (is_delim (c1) || c1 == eol1 || c1 == eol2) | 3899 if (is_delim (c1) || c1 == eol1 || c1 == eol2) |
3900 { | 3900 { |
3901 is.get (); | 3901 is.get (); |
3902 if (c1 == eol1 && is.peek_undelim () == eol2) | 3902 if (c1 == eol1 && is.peek_undelim () == eol2) |
3942 if (multiple_delims_as_one) | 3942 if (multiple_delims_as_one) |
3943 { | 3943 { |
3944 int prev = -1; | 3944 int prev = -1; |
3945 // skip multiple delims. | 3945 // skip multiple delims. |
3946 // Increment lines for each end-of-line seen; for \r\n, decrement | 3946 // Increment lines for each end-of-line seen; for \r\n, decrement |
3947 while (is && ((c1 = skip_whitespace (is, true)) | 3947 while (is && ((c1 = skip_whitespace (is)) |
3948 != std::istream::traits_type::eof ()) | 3948 != std::istream::traits_type::eof ()) |
3949 && (((c1 == eol1 || c1 == eol2) && ++lines) | 3949 && (((c1 == eol1 || c1 == eol2) && ++lines) |
3950 || -1 != lookahead (is, delim_list, delim_len))) | 3950 || -1 != lookahead (is, delim_list, delim_len))) |
3951 { | 3951 { |
3952 if (prev == eol1 && eol1 != eol2 && c1 == eol2) | 3952 if (prev == eol1 && eol1 != eol2 && c1 == eol2) |