Mercurial > octave-nkf
changeset 5678:52323f13c86b
[project @ 2006-03-16 06:45:08 by jwe]
author | jwe |
---|---|
date | Thu, 16 Mar 2006 06:45:25 +0000 |
parents | a8f6903535c9 |
children | 297b82335c7b |
files | scripts/ChangeLog scripts/strings/strfind.m test/ChangeLog test/test_system.m |
diffstat | 4 files changed, 84 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog Thu Mar 16 05:57:18 2006 +0000 +++ b/scripts/ChangeLog Thu Mar 16 06:45:25 2006 +0000 @@ -1,3 +1,7 @@ +2006-03-16 William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> + + * strings/strfind.m: New file. + 2006-03-16 John W. Eaton <jwe@octave.org> * general/rows.m, general/columns.m: Delete. @@ -6,7 +10,7 @@ * strings/strcmpi.m: Simplify. * strings/strncmpi.m: Import from octave-forge, simplify. - * strings/strtrunc.m: New function. + * strings/strtrunc.m: New file. * strings/lower.m, strings/upper.m: Handle cellstr arguments.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/strings/strfind.m Thu Mar 16 06:45:25 2006 +0000 @@ -0,0 +1,66 @@ +## Copyright (C) 2004 by Alois Schloegl +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{idx} =} strfind (@var{str}, @var{pattern}) +## @deftypefnx {Function File} {@var{idx} =} strfind (@var{cellstr}, @var{pattern}) +## Search for @var{pattern} in the string @var{str} and return the +## starting index of every such occurrence in the vector @var{idx}. +## If there is no such occurrence, or if @var{pattern} is longer +## than @var{str}, then @var{idx} is the empty array @code{[]}. +## +## If the cell array of strings @var{cellstr} is specified instead of the +## string @var{str}, then @var{idx} is a cell array of vectors, as specified +## above. +## @seealso{findstr, strmatch, strcmp, strncmp, strcmpi, strncmpi} +## @end deftypefn + +## Author: alois schloegl <a.schloegl@ieee.org> +## Created: 1 November 2004 +## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> + +function idx = strfind (text, pattern) + + if (nargin != 2) + usage ("idx = strfind (text, pattern)"); + elseif (! ischar (pattern)) + error ("strfind: pattern must be a string value"); + endif + + lp = length (pattern); + + if (ischar (text)) + idx = __strfind_string__ (text, pattern, lp); + elseif (iscellstr (text)) + idx = cell (size (text)); + for i = 1:(numel (text)) + idx{i} = __strfind_string__ (text{i}, pattern, lp); + endfor + else + error ("strfind: text must be a string or cell array of strings"); + endif + +### endfunction + +function idx = __strfind_string__ (text, pattern, lp) + + idx = 1:(length (text) - lp + 1); + k = 0; + while (k < lp && ! isempty (idx)) + idx = idx(text(idx + k) == pattern(++k)); + endwhile + +### endfunction
--- a/test/ChangeLog Thu Mar 16 05:57:18 2006 +0000 +++ b/test/ChangeLog Thu Mar 16 06:45:25 2006 +0000 @@ -1,3 +1,8 @@ +2006-03-16 John W. Eaton <jwe@octave.org> + + * test_system.m: End all *pwent tests with a call to endpwent. + End all *grent tests with a call to endgrent. + 2006-03-14 John W. Eaton <jwe@octave.org> * fntests.m: Prettier printing of output.
--- a/test/test_system.m Thu Mar 16 05:57:18 2006 +0000 +++ b/test/test_system.m Thu Mar 16 06:45:25 2006 +0000 @@ -468,6 +468,7 @@ %% test/octave.test/system/getpwent-1.m %!test %! s = getpwent (); +%! endpwent (); %! assert((isstruct (s) %! && struct_contains (s, "name") %! && struct_contains (s, "passwd") @@ -484,7 +485,7 @@ %!test %! x = getpwent (); %! y = getpwuid (x.uid); -%! +%! endpwent (); %! assert(strcmp (x.name, y.name) && x.uid == y.uid && x.gid == y.gid); %% test/octave.test/system/getpwuid-2.m @@ -497,7 +498,7 @@ %!test %! x = getpwent (); %! y = getpwnam (x.name); -%! +%! endpwent (); %! assert(strcmp (x.name, y.name) && x.uid == y.uid && x.gid == y.gid); %% test/octave.test/system/getpwnam-2.m @@ -511,7 +512,7 @@ %! x = getpwent (); %! setpwent (); %! y = getpwent (); -%! +%! endpwent (); %! assert(strcmp (x.name, y.name) && x.uid == y.uid && x.gid == y.gid); %% test/octave.test/system/setpwent-2.m @@ -523,6 +524,7 @@ %% test/octave.test/system/getgrent-1.m %!test %! x = getgrent (); +%! endgrent (); %! assert((isstruct (x) %! && struct_contains (x, "name") %! && struct_contains (x, "passwd") @@ -536,7 +538,7 @@ %!test %! x = getgrent (); %! y = getgrgid (x.gid); -%! +%! endgrent (); %! assert(strcmp (x.name, y.name) && x.gid == y.gid); %% test/octave.test/system/getgrgid-2.m @@ -549,7 +551,7 @@ %!test %! x = getgrent (); %! y = getgrnam (x.name); -%! +%! endgrent (); %! assert(strcmp (x.name, y.name) && x.gid == y.gid); %% test/octave.test/system/getgrnam-2.m @@ -563,7 +565,7 @@ %! x = getgrent (); %! setgrent (); %! y = getgrent (); -%! +%! endgrent (); %! assert(strcmp (x.name, y.name) && x.gid == y.gid); %% test/octave.test/system/setgrent-2.m