# HG changeset patch # User Erik Kjellson # Date 1367773905 -7200 # Node ID 1cfa3a49247f30083c9d105e401ffa21dd850ce3 # Parent cfacb0446066dbe382004dd0b4d0e8854fd1e57c importdata.m: Added Carriage Return as possible line break character. diff -r cfacb0446066 -r 1cfa3a49247f scripts/io/importdata.m --- a/scripts/io/importdata.m Mon May 13 08:59:05 2013 -0400 +++ b/scripts/io/importdata.m Sun May 05 19:11:45 2013 +0200 @@ -1,4 +1,4 @@ -## Copyright (C) 2012 Erik Kjellson +## Copyright (C) 2012-2013 Erik Kjellson ## ## This file is part of Octave. ## @@ -59,7 +59,6 @@ ## @seealso{textscan, dlmread, csvread, load} ## @end deftypefn -## Author: Erik Kjellson function [output, delimiter, header_rows] = importdata (varargin) @@ -193,8 +192,8 @@ ## Read file into string and count the number of header rows file_content = fileread (fname); - ## Split the file into rows (using \r\n or \n as delimiters between rows). - file_content_rows = regexp (file_content, "\r?\n", "split"); + ## Split the file into rows (using \n and/or \r as delimiters between rows). + file_content_rows = regexp (file_content, "\n|\n\r|\r|\r\n", "split"); ## FIXME: guess delimiter, if it isn't defined if (isempty (delimiter)) @@ -434,3 +433,16 @@ %! assert (d, "\t"); %! assert (h, 0); +%!test +%! # CR for line breaks +%! A = [3.1 -7.2 0; 0.012 6.5 128]; +%! fn = tmpnam (); +%! fid = fopen (fn, "w"); +%! fputs (fid, "3.1\t-7.2\t0\r0.012\t6.5\t128"); +%! fclose (fid); +%! [a,d,h] = importdata (fn, "\\t"); +%! unlink (fn); +%! assert (a, A); +%! assert (d, "\t"); +%! assert (h, 0); +