# HG changeset patch # User John W. Eaton # Date 1217861986 14400 # Node ID e633fd6ed0493f787bc0da53b589c6121e18c743 # Parent 642af2e62b1f0a30839b41c1f373528036fbccbe strtok.m: include TAB, LF, VT, FF, and CR in default set of delim characters diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2008-08-04 John W. Eaton + + * strings/strtok.m: Include TAB, LF, VT, FF, and CR in default + list of delim characters. Update tests. + 2008-06-11 John W. Eaton * general/rat.m: Properly initialize steps when all elements of diff --git a/scripts/strings/strtok.m b/scripts/strings/strtok.m --- a/scripts/strings/strtok.m +++ b/scripts/strings/strtok.m @@ -35,7 +35,7 @@ endif if (nargin < 2 || isempty (delim)) - delim = " "; + delim = "\t\n\v\f\r "; endif if (isempty (str)) @@ -114,12 +114,12 @@ %!# test the remainder for all cases %!test [t,r] = strtok(""); assert(r, ""); -%!test [t,r] = strtok("this"); assert(r, ""); +%!test [t,r] = strtok("this"); assert(r, char (zeros (1, 0))); %!test [t,r] = strtok("this "); assert(r, " "); %!test [t,r] = strtok("this is"); assert(r, " is"); -%!test [t,r] = strtok(" this"); assert(r, ""); +%!test [t,r] = strtok(" this"); assert(r, char (zeros (1, 0))); %!test [t,r] = strtok(" this "); assert(r, " "); -%!test [t,r] = strtok(" "); assert(r, ""); +%!test [t,r] = strtok(" "); assert(r, char (zeros (1, 0))); %!# simple check with 2 and 3 delimeters %!assert(strtok("this is", "i "), "th"); @@ -138,3 +138,11 @@ %!# test 'bad' string orientations %!assert(strtok(" this "'), "this"'); # delimiter at start and end %!assert(strtok(" this "',"jkl "), "this"'); + +%!# test with TAB, LF, VT, FF, and CR +%!test +%! for ch = "\t\n\v\f\r" +%! [t, r] = strtok (cstrcat ("beg", ch, "end")); +%! assert (t, "beg"); +%! assert (r, cstrcat (ch, "end")) +%! endfor