diff libinterp/corefcn/file-io.cc @ 26706:ccea3574f36b

Support encoding of file streams in textscan (bug #55452). * oct-stream.cc (do_textscan): Pass encoding in constructor for textscan object. (textscan): Store encoding in object. Convert strings from encoding. * file-io.cc (textscan): Add BIST. * io.tst (fopen): Use code page identifier that better works cross-platform.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 09 Feb 2019 20:05:47 +0100
parents c13143821eef
children 7506884fc158
line wrap: on
line diff
--- a/libinterp/corefcn/file-io.cc	Sat Feb 09 17:41:48 2019 +0100
+++ b/libinterp/corefcn/file-io.cc	Sat Feb 09 20:05:47 2019 +0100
@@ -2267,6 +2267,19 @@
 %! obs = textscan (str, "%f", "delimiter", {",",";","$"});
 %! assert (obs, { [0; 1; NaN; 2; 3] });
 
+## file stream with encoding
+%!test
+%! f = tempname ();
+%! fid = fopen (f, "w+", "n", "iso-8859-1");
+%! unwind_protect
+%!   fprintf (fid, "abc,äöü\n");
+%!   fseek (fid, 0, "bof");
+%!   obs = textscan (fid, "%s", "delimiter", ",");
+%!   fclose (fid);
+%!   assert (obs, { {"abc"; "äöü"} });
+%! unwind_protect_cleanup
+%!   unlink (f);
+%! end_unwind_protect
 */
 
 // These tests have end-comment sequences, so can't just be in a comment