changeset 30790:5fbc41f7a8d1

textscan: Reposition scan pointer after reading a single `.` (bug #60711). * oct-stream.cc (textscan::read_double): When a single `.` is encountered, it is indeed considered an invalid character. But it must also be put back because, unlike any other invalid character, it has caused an additional `get()` call above. This then allows the various tests for the presence of a delimiter on the next character to fail (e.g., in `textscan::read_format_once()` and `textscan_format_list::read_first_row()`), and thus finally allows `textscan()` builtin to exit correctly in error. * file-io.cc (Ftextscan): Add BIST. * doc/interpreter/contributors.in: Add new contributor to list in manual.
author Gaël Bonithon <gael@xfce.org>
date Mon, 28 Feb 2022 11:48:29 +0100
parents 00ccd10a09e0
children 85a580a6b292
files doc/interpreter/contributors.in libinterp/corefcn/file-io.cc libinterp/corefcn/oct-stream.cc
diffstat 3 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/contributors.in	Mon Feb 28 08:36:29 2022 +0100
+++ b/doc/interpreter/contributors.in	Mon Feb 28 11:48:29 2022 +0100
@@ -34,6 +34,7 @@
 David Billinghurst
 Don Bindner
 Jakub Bogusz
+Gaƫl Bonithon
 Moritz Borgmann
 Paul Boven
 Richard Bovey
--- a/libinterp/corefcn/file-io.cc	Mon Feb 28 08:36:29 2022 +0100
+++ b/libinterp/corefcn/file-io.cc	Mon Feb 28 11:48:29 2022 +0100
@@ -2328,6 +2328,8 @@
 %! C = textscan ('5973459727478852968', '%u64');
 %! assert (C{1}, uint64 (5973459727478852968));
 
+%!assert <*60711> (textscan('1,.,2', '%f', 'Delimiter', ','), {1});
+
 */
 
 // These tests have end-comment sequences, so can't just be in a comment
--- a/libinterp/corefcn/oct-stream.cc	Mon Feb 28 08:36:29 2022 +0100
+++ b/libinterp/corefcn/oct-stream.cc	Mon Feb 28 11:48:29 2022 +0100
@@ -2851,6 +2851,11 @@
 
         if (i > 0)
           valid = true;           // valid if at least one digit after '.'
+        else if (! valid)         // if there was nothing before and after '.'
+          {
+            is.putback (ch);
+            ch = '.';
+          }
 
         // skip remainder after '.', to field width, to look for exponent
         if (i == precision)