comparison scripts/io/strread.m @ 20035:f68c3a62e42c

strread.m: properly process traling delimiters in case of MultipleDelimsAsOne parameter (bug #44750)
author Philip Nienhuis <prnienhuis@users.sf.net>
date Mon, 06 Apr 2015 23:05:41 +0200
parents e9f89866074c
children e51473fdb622
comparison
equal deleted inserted replaced
20034:42c3a0829324 20035:f68c3a62e42c
803 803
804 ## Split text string along delimiters 804 ## Split text string along delimiters
805 out = ostrsplit (text, sep, mult_dlms_s1); 805 out = ostrsplit (text, sep, mult_dlms_s1);
806 if (index (sep, eol_char)); out = strrep (out, char (255), ''); endif 806 if (index (sep, eol_char)); out = strrep (out, char (255), ''); endif
807 ## In case of trailing delimiter, strip stray last empty word 807 ## In case of trailing delimiter, strip stray last empty word
808 if (! isempty (out) && any (sep == text(end))) 808 if (! isempty (out) && any (sep == text(end)) && ! mult_dlms_s1)
809 out(end) = []; 809 out(end) = [];
810 endif 810 endif
811 811
812 ## Empty cells converted to empty cellstrings. 812 ## Empty cells converted to empty cellstrings.
813 out(cellfun ("isempty", out)) = {""}; 813 out(cellfun ("isempty", out)) = {""};
934 %! [a b c d] = strread (str, "%f %f %f %f", "delimiter", ",", "multipledelimsasone", 1, "endofline", "\n"); 934 %! [a b c d] = strread (str, "%f %f %f %f", "delimiter", ",", "multipledelimsasone", 1, "endofline", "\n");
935 %! assert (a', [11, 21, NaN]); 935 %! assert (a', [11, 21, NaN]);
936 %! assert (b', [12, 23, 33]); 936 %! assert (b', [12, 23, 33]);
937 %! assert (c', [13, 24, 34]); 937 %! assert (c', [13, 24, 34]);
938 %! assert (d', [15, 25, 35]); 938 %! assert (d', [15, 25, 35]);
939
940 ## Bug #44750
941 %!test
942 %! assert (strread ('/home/foo/','%s','delimiter','/','MultipleDelimsAsOne',1), ...
943 %! {"home"; "foo"});
939 944
940 ## delimiter as sq_string and dq_string 945 ## delimiter as sq_string and dq_string
941 %!test 946 %!test
942 %! assert (strread ("1\n2\n3", "%d", "delimiter", "\n"), 947 %! assert (strread ("1\n2\n3", "%d", "delimiter", "\n"),
943 %! strread ("1\n2\n3", "%d", "delimiter", '\n')) 948 %! strread ("1\n2\n3", "%d", "delimiter", '\n'))