Mercurial > octave
diff libinterp/corefcn/file-io.cc @ 30822:0826c503f294
Encoding facet based on gnulib uniconv for STL iostreams (bug #61839).
* liboctave/util/oct-string.h, liboctave/util/oct-string.cc (codecvt_u8): Add
encoding facet based on gnulib uniconv for STL iostreams.
* liboctave/wrappers/uniconv-wrappers.h, liboctave/wrappers/uniconv-wrappers.c
(octave_u8_conv_from_encoding_offsets, octave_u8_conv_to_encoding_offsets): Add
new wrappers.
* libinterp/corefcn/oct-stream.h, libinterp/corefcn/oct-stream.cc
(octave::stream): Wrap output stream with encoding facet.
* libinterp/corefcn/utils.h, libinterp/corefcn/utils.cc (format, vformat):
Remove functions that are no longer needed.
* libinterp/corefcn/file-io.cc: Add BIST.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sat, 05 Mar 2022 21:20:58 +0100 |
parents | 5fbc41f7a8d1 |
children | 1921d9d0e62b |
line wrap: on
line diff
--- a/libinterp/corefcn/file-io.cc Sun Mar 06 18:20:05 2022 -0800 +++ b/libinterp/corefcn/file-io.cc Sat Mar 05 21:20:58 2022 +0100 @@ -904,6 +904,34 @@ return puts_internal (interp, who, args); } +/* +## Check if text is correctly converted to output encoding +%!test <*61839> +%! str = "aäöu"; # string with non-ASCII characters +%! fname = tempname (); +%! fid = fopen (fname, "wt", "n", "ISO-8859-1"); +%! unwind_protect +%! fprintf (fid, '%s\n', str); +%! fdisp (fid, str); +%! fputs (fid, str); +%! fclose (fid); +%! ## re-open file for reading in binary mode +%! fid = fopen (fname, "rb"); +%! fb = fread (fid); +%! fclose (fid); +%! ## check file content +%! encoded = [97 228 246 117]; # original string in ISO-8859-1 encoding +%! if (ispc ()) +%! eol = double ("\r\n"); +%! else +%! eol = double ("\n"); +%! endif +%! assert (fb.', [encoded eol encoded eol encoded]) +%! unwind_protect_cleanup +%! unlink (fname); +%! end_unwind_protect +*/ + DEFMETHOD (puts, interp, args, , doc: /* -*- texinfo -*- @deftypefn {} {} puts (@var{string}) @@ -2277,6 +2305,7 @@ %! fid = fopen (f, "w+", "n", "iso-8859-1"); %! unwind_protect %! fprintf (fid, "abc,äöü\n"); +%! fflush (fid); %! fseek (fid, 0, "bof"); %! obs = textscan (fid, "%s", "delimiter", ","); %! fclose (fid);