octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[changeset] string functions: fix docstrings, add examples, references a


From: Thorsten Meyer
Subject: [changeset] string functions: fix docstrings, add examples, references and tests
Date: Fri, 26 Dec 2008 23:44:49 +0100
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

Hi,

attached is a changeset for documentation strings and tests of the string 
functions. In addition, it
fixes one missing semicolon and two nargin checks.

Note that Francescos strrep patch (he sent today) will not cleanly apply on top 
of this changeset
(looking at it, I do not really understand why).

regards

Thorsten

# HG changeset patch
# User Thorsten Meyer <address@hidden>
# Date 1230331205 -3600
# Node ID 14dbaf03110c428816ad809fbace5b50dfd8bbbd
# Parent  a84d71abdc5bb445c9706cc767b898b8d23f07b5
Fix docstrings, add examples, references and tests to string functions

diff -r a84d71abdc5b -r 14dbaf03110c doc/ChangeLog
--- a/doc/ChangeLog     Wed Dec 24 16:45:11 2008 -0500
+++ b/doc/ChangeLog     Fri Dec 26 23:40:05 2008 +0100
@@ -0,0 +1,4 @@
+2008-12-26  Thorsten Meyer  <address@hidden>
+
+       * interpreter/strings.txi: Add space to ischar example.
+       
diff -r a84d71abdc5b -r 14dbaf03110c doc/interpreter/strings.txi
--- a/doc/interpreter/strings.txi       Wed Dec 24 16:45:11 2008 -0500
+++ b/doc/interpreter/strings.txi       Fri Dec 26 23:40:05 2008 +0100
@@ -184,8 +184,10 @@
 @group
 ischar(collection)
      @result{} ans = 1
+
 ischar(collection) && isvector(collection)
      @result{} ans = 0
+
 ischar("my string") && isvector("my string")
      @result{} ans = 1
 @end group
diff -r a84d71abdc5b -r 14dbaf03110c scripts/ChangeLog
--- a/scripts/ChangeLog Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/ChangeLog Fri Dec 26 23:40:05 2008 +0100
@@ -0,0 +1,15 @@
+2008-12-26  Thorsten Meyer  <address@hidden>
+
+       * general/int2str.m, general/num2str.m, strings/base2dec.m,
+       strings/blanks.m, strings/cstrcat.m, strings/findstr.m,
+       strings/isstrprop.m, strings/mat2str.m, strings/regexptranslate.m,
+       strings/split.m, strings/str2double.m, strings/str2num.m,
+       strings/strcat.m, strings/strcmpi.m, strings/strfind.m,
+       strings/strjust.m, strings/strmatch.m, strings/strncmpi.m,
+       strings/strrep.m, strings/strtok.m, strings/strtrim.m,
+       strings/strtrunc.m, strings/strvcat.m, strings/substr.m: 
+       Fix documentation strings, add examples, references and tests.
+       * scripts/general/int2str.m: Add missing semicolon.
+       * scripts/strings/regexptranslate.m: add nargin check.
+       * scripts/strings/str2double.m: fix nargin check.
+       
diff -r a84d71abdc5b -r 14dbaf03110c scripts/general/int2str.m
--- a/scripts/general/int2str.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/general/int2str.m Fri Dec 26 23:40:05 2008 +0100
@@ -19,10 +19,31 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} int2str (@var{n})
-## Convert an integer to a string.  This function is not very flexible.
-## For better control over the results, use @code{sprintf}
-## (@pxref{Formatted Output}). 
-## @seealso{sprintf, num2str}
+## Convert an integer (or array of integers) to a string (or a character
+## array).
+##
+## @example
+## @group
+##
+## int2str (123)
+##      @result{} "123"
+##
+## s = int2str ([1, 2, 3; 4, 5, 6])
+##      @result{} s = 
+##         1  2  3
+##         4  5  6
+## 
+## whos s
+##      @result{} s = 
+##       Attr Name        Size                     Bytes  Class
+##       ==== ====        ====                     =====  ===== 
+##            s           2x7                         14  char
+## @end group
+## @end example
+##
+## This function is not very flexible.  For better control over the
+## results, use @code{sprintf} (@pxref{Formatted Output}). 
+## @seealso{sprintf, num2str, mat2str}
 ## @end deftypefn
 
 ## Author: jwe
@@ -43,7 +64,7 @@
       ifmt = get_fmt (x(idx{:}), 0);
       idx(2) = 2:sz(2);
       rfmt = get_fmt (x(idx{:}), 2);
-      fmt = cstrcat (ifmt, repmat (rfmt, 1, nc-1), "\n")
+      fmt = cstrcat (ifmt, repmat (rfmt, 1, nc-1), "\n");
     else
       fmt = cstrcat (get_fmt (x, 0), "\n");
     endif
@@ -93,8 +114,7 @@
 endfunction
 
 %!assert(strcmp (int2str (-123), "-123") && strcmp (int2str (1.2), "1"));
-
+%!assert (all (int2str ([1, 2, 3; 4, 5, 6]) == ["1  2  3";"4  5  6"]));
 %!error int2str ();
-
 %!error int2str (1, 2);
 
diff -r a84d71abdc5b -r 14dbaf03110c scripts/general/num2str.m
--- a/scripts/general/num2str.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/general/num2str.m Fri Dec 26 23:40:05 2008 +0100
@@ -18,13 +18,45 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} num2str (@var{n})
+## @deftypefn {Function File} {} num2str (@var{x})
 ## @deftypefnx {Function File} {} num2str (@var{x}, @var{precision})
 ## @deftypefnx {Function File} {} num2str (@var{x}, @var{format})
-## Convert a number to a string.  This function is not very flexible.
-## For better control over the results, use @code{sprintf}
-## (@pxref{Formatted Output}).
-## @seealso{sprintf, int2str}
+## Convert a number (or array) to a string (or a character array).  The
+## optional second argument may either give the number of significant
+## digits (@var{precision}) to be used in the output or a format
+## template string (@var{format}) as in @code{sprintf} (@pxref{Formatted
+## Output}).  @code{num2str} can also handle complex numbers.  For
+## example: 
+##
+## @example
+## @group
+## num2str (123.456)
+##      @result{} "123.46"
+##
+## num2str (123.456, 4)
+##      @result{} "123.5"
+##
+## s = num2str ([1, 1.34; 3, 3.56], "%5.1f")
+##      @result{} s =
+##         1.0  1.3
+##         3.0  3.6
+## whos s
+##      @result{}
+##       Attr Name        Size                     Bytes  Class
+##       ==== ====        ====                     =====  ===== 
+##            s           2x8                         16  char
+##
+## num2str (1.234 + 27.3i)
+##      @result{} "1.234+27.3i"
+## @end group
+## @end example
+##
+## The @code{num2str} function is not very flexible.  For better control
+## over the results, use @code{sprintf} (@pxref{Formatted Output}). 
+## Note that for complex @var{x}, the format string may only contain one
+## output conversion specification and nothing else.  Otherwise, you
+## will get unpredictable results.  
+## @seealso{sprintf, int2str, mat2str}
 ## @end deftypefn
 
 ## Author: jwe
@@ -149,9 +181,10 @@
 
 endfunction
 
-%!assert((strcmp (num2str (123), "123") && strcmp (num2str (1.23), "1.23")));
-
+%!assert ((strcmp (num2str (123), "123") && strcmp (num2str (1.23), "1.23")));
+%!assert (num2str (123.456, 4), "123.5");
+%!assert (all (num2str ([1, 1.34; 3, 3.56], "%5.1f") == ["1.0  1.3"; "3.0  
3.6"]));
+%!assert (num2str (1.234 + 27.3i), "1.234+27.3i");
 %!error num2str ();
-
 %!error num2str (1, 2, 3);
 
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/base2dec.m
--- a/scripts/strings/base2dec.m        Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/base2dec.m        Fri Dec 26 23:40:05 2008 +0100
@@ -81,3 +81,9 @@
   out = d * (base .^ (columns(d)-1 : -1 : 0)');
 
 endfunction
+
+%!error <Invalid call to base2dec.*> base2dec();
+%!error <Invalid call to base2dec.*> base2dec("11120");
+%!error <Invalid call to base2dec.*> base2dec("11120", 3, 4);
+%!assert(base2dec ("11120", 3), 123);
+%!assert(base2dec ("yyyzx", "xyz"), 123);
\ No newline at end of file
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/blanks.m
--- a/scripts/strings/blanks.m  Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/blanks.m  Fri Dec 26 23:40:05 2008 +0100
@@ -19,7 +19,18 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} blanks (@var{n})
-## Return a string of @var{n} blanks.
+## Return a string of @var{n} blanks, for example:
+##
+## @example
+## @group
+## blanks(10);
+## whos ans;
+##      @result{}
+##       Attr Name        Size                     Bytes  Class
+##       ==== ====        ====                     =====  ===== 
+##            ans         1x10                        10  char
+## @end group
+## @end example
 ## @seealso{repmat}
 ## @end deftypefn
 
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/cstrcat.m
--- a/scripts/strings/cstrcat.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/cstrcat.m Fri Dec 26 23:40:05 2008 +0100
@@ -19,16 +19,26 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} cstrcat (@var{s1}, @var{s2}, @dots{})
-## Return a string containing all the arguments concatenated.  For example,
+## Return a string containing all the arguments concatenated
+## horizontally. Trailing white space is preserved. For example,
+##
+## @example
+## @group
+## cstrcat ("ab   ", "cd")
+##      @result{} "ab   cd"
+## @end group
+## @end example
 ##
 ## @example
 ## @group
 ## s = [ "ab"; "cde" ];
 ## cstrcat (s, s, s)
-##      @result{} "ab ab ab "
+##      @result{} ans =
+##         "ab ab ab "
 ##         "cdecdecde"
 ## @end group
 ## @end example
+## @seealso{strcat, char, strvcat}
 ## @end deftypefn
 
 ## Author: jwe
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/findstr.m
--- a/scripts/strings/findstr.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/findstr.m Fri Dec 26 23:40:05 2008 +0100
@@ -25,11 +25,14 @@
 ## can include overlapping positions (this is the default).  For example,
 ##
 ## @example
+## @group
 ## findstr ("ababab", "a")
-##      @result{} [ 1, 3, 5 ]
+##      @result{} [1, 3, 5]
 ## findstr ("abababa", "aba", 0)
-##      @result{} [ 1, 5 ]
+##      @result{} [1, 5]
+## @end group
 ## @end example
+## @seealso{strfind, strmatch, strcmp, strncmp, strcmpi, strncmpi, find}
 ## @end deftypefn
 
 ## Note that this implementation swaps the strings if second one is longer
@@ -129,7 +132,7 @@
 
 endfunction
 
-%!assert((findstr ("abababa", "a") == [1, 3, 5, 7]
+%!assert ((findstr ("abababa", "a") == [1, 3, 5, 7]
 %! && findstr ("abababa", "aba") == [1, 3, 5]
 %! && findstr ("abababa", "aba", 0) == [1, 5]));
 
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/isletter.m
--- a/scripts/strings/isletter.m        Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/isletter.m        Fri Dec 26 23:40:05 2008 +0100
@@ -18,7 +18,7 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} isletter (@var{s})
-## Returns true if @var{s} is a letter false otherwise.
+## Returns true if @var{s} is a letter, false otherwise.
 ## @seealso{isalpha}
 ## @end deftypefn
 
@@ -33,3 +33,6 @@
   retval = isalpha (s);
 
 endfunction
+
+%!error isletter();
+%!error isletter("a", "b");
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/isstrprop.m
--- a/scripts/strings/isstrprop.m       Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/isstrprop.m       Fri Dec 26 23:40:05 2008 +0100
@@ -22,7 +22,7 @@
 ##
 ## @example
 ## @group
-## isstrprop ("abc123", "isalpha")
+## isstrprop ("abc123", "alpha")
 ## @result{} [1, 1, 1, 0, 0, 0]
 ## @end group
 ## @end example
@@ -116,3 +116,6 @@
   endif
 
 endfunction
+
+%!error <invalid predicate> isstrprop ("abc123", "foo");
+%!assert (isstrprop ("abc123", "alpha"), logical ([1, 1, 1, 0, 0, 0]));
\ No newline at end of file
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/mat2str.m
--- a/scripts/strings/mat2str.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/mat2str.m Fri Dec 26 23:40:05 2008 +0100
@@ -36,16 +36,18 @@
 ##
 ## @example
 ## @group
-##    mat2str( [ -1/3 + i/7; 1/3 - i/7 ], [4 2] )
-##    @result{} '[-0.3333+0.14i;0.3333-0.14i]'
-##    mat2str( [ -1/3 +i/7; 1/3 -i/7 ], [4 2] )
-##    @result{} '[-0.3333+0i,0+0.14i;0.3333+0i,-0-0.14i]'
-##    mat2str( int16([1 -1]), 'class')
-##    @result{} 'int16([1,-1])'
+## mat2str( [ -1/3 + i/7; 1/3 - i/7 ], [4 2] )
+##      @result{} "[-0.3333+0.14i;0.3333-0.14i]"
+##
+## mat2str( [ -1/3 +i/7; 1/3 -i/7 ], [4 2] )
+##      @result{} "[-0.3333+0i,0+0.14i;0.3333+0i,-0-0.14i]"
+##
+## mat2str( int16([1 -1]), 'class')
+##      @result{} "int16([1,-1])"
 ## @end group
 ## @end example
 ##
-## @seealso{sprintf, int2str}
+## @seealso{sprintf, num2str, int2str}
 ## @end deftypefn
 
 ## Author: Rolf Fabian <address@hidden>
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/regexptranslate.m
--- a/scripts/strings/regexptranslate.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/regexptranslate.m Fri Dec 26 23:40:05 2008 +0100
@@ -26,16 +26,33 @@
 ## @table @asis
 ## @item "wildcard"
 ## The wildcard characters @code{.}, @code{*} and @code{?} are replaced
-## with wildcards that are appropriate for a regular expression.
-##
+## with wildcards that are appropriate for a regular expression. For example:
+## @example
+## @group
+## regexptranslate ("wildcard", "*.m")
+##      @result{} ".*\.m"
+## @end group
+## @end example
+## 
 ## @item "escape"
 ## The characters @code{$.?[]}, that have special meaning for regular
-## expressions are escaped so that they are treated literally.
+## expressions are escaped so that they are treated literally. For example:
+## @example
+## @group
+## regexptranslate ("escape", "12.5")
+##      @result{} "12\.5"
+## @end group
+## @end example
 ## @end table
+## @seealso{regexp, regexpi, regexprep}
 ## @end deftypefn
 
 function y = regexptranslate (op, x)
   
+  if nargin != 2
+    print_usage ();
+  endif 
+  
   if (ischar (op))
     op = tolower (op);
     if (strcmp ("wildcard", op))
@@ -55,5 +72,10 @@
   endif
 endfunction
 
+%!error <Invalid call to regexptranslate> regexptranslate ();
+%!error <Invalid call to regexptranslate> regexptranslate ("wildcard");
+%!error <Invalid call to regexptranslate> regexptranslate ("a", "b", "c");
+%!error <unexpected operation> regexptranslate ("foo", "abc");
+%!error <expecting operation to be a string> regexptranslate (10, "abc");
 %!assert (regexptranslate ("wildcard", "/a*b?c."), "/a.*b.c\\.")
 %!assert (regexptranslate ("escape", '$.?[]'), '\$\.\?\[\]')
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/split.m
--- a/scripts/strings/split.m   Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/split.m   Fri Dec 26 23:40:05 2008 +0100
@@ -27,16 +27,19 @@
 ##
 ## @example
 ## split ("Test string", "t")
-##      @result{} "Tes "
+##      @result{}
+##         "Tes "
 ##         " s  "
 ##         "ring"
 ## @end example
 ##
 ## @example
-## split ("Test string", "t", 2)
-##      @result{} "Tes    "
-##         " string"
+## split ("Test string", "t s", 2)
+##      @result{}
+##         "Tes  "
+##         "tring"
 ## @end example
+## @seealso{strtok, index}
 ## @end deftypefn
 
 ## Author: Kurt Hornik <address@hidden>
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/str2double.m
--- a/scripts/strings/str2double.m      Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/str2double.m      Fri Dec 26 23:40:05 2008 +0100
@@ -59,6 +59,7 @@
 ## Examples:
 ##
 ## @example
+## @group
 ## str2double ("-.1e-5")
 ## @result{} -1.0000e-006
 ##
@@ -73,7 +74,9 @@
 ##     200   300   NaN  -Inf   NaN   NaN   999   NaN   NaN
 ## @result{} status =
 ##       0     0     0     0    -1    -1     0    -1     0
+## @end group
 ## @end example
+## @seealso{str2num}
 ## @end deftypefn
 
 ## Author: Alois Schloegl <address@hidden>
@@ -87,8 +90,8 @@
   ## valid delimiters
   valid_delim = char (sort ([0, 9:14, 32:34, abs("()[]{},;:\"|/")]));
 
-  if (nargin < 1)
-    error ("missing input argument");
+  if (nargin < 1 || nargin > 4)
+    print_usage ();
   endif
 
   if (nargin < 2)
@@ -277,3 +280,14 @@
   endfor
 
 endfunction
+
+%!error <Invalid call to str2double> str2double();
+%!error <Invalid call to str2double> str2double("1e10", " ", "\n", ".", "x");
+%!assert (str2double ("-.1e-5"), -1.0000e-006);
+%!assert (str2double (".314e1, 44.44e-1, .7; -1e+1"),
+%!  [3.1400, 4.4440, 0.7000; -10.0000, NaN, NaN]);
+%!test
+%!  line = "200, 300, NaN, -inf, yes, no, 999, maybe, NaN";
+%!  [x, status] = str2double (line);
+%!  assert (x, [200, 300, NaN, -Inf, NaN, NaN, 999, NaN, NaN]);
+%!  assert (status, [0, 0, 0, 0, -1, -1, 0, -1, 0]);
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/str2num.m
--- a/scripts/strings/str2num.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/str2num.m Fri Dec 26 23:40:05 2008 +0100
@@ -18,7 +18,26 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} str2num (@var{s})
-## Convert the string @var{s} to a number.
+## Convert the string (or character array) @var{s} to a number (or an
+## array). Examples:  
+##
+## @example
+## @group
+## str2num("3.141596")
+##      @result{} 3.141596
+## 
+## str2num(["1, 2, 3"; "4, 5, 6"]);
+##      @result{} ans =
+##         1  2  3
+##         4  5  6
+## @end group
+## @end example
+## 
+## @strong{Caution:} As @code{str2num} uses the @code{eval} function
+## to do the conversion, @code{str2num} will execute any code contained
+## in the string @var{s}.  Use @code{str2double} instead if you want to
+## avoid the use of @code{eval}. 
+## @seealso{str2double, eval}
 ## @end deftypefn
 
 ## Author: jwe
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strcat.m
--- a/scripts/strings/strcat.m  Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strcat.m  Fri Dec 26 23:40:05 2008 +0100
@@ -19,16 +19,36 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} strcat (@var{s1}, @var{s2}, @dots{})
-## Return a string containing all the arguments concatenated.  For example,
+## Return a string containing all the arguments concatenated
+## horizontally.  If the arguments are cells strings,  @code{strcat}
+## returns a cell string with the individual cells concatenated.
+## For numerical input, each element is converted to the
+## corresponding ASCII character. Trailing white space is eliminated.
+## For example,
 ##
 ## @example
 ## @group
 ## s = [ "ab"; "cde" ];
 ## strcat (s, s, s)
-##      @result{} "ab ab ab "
+##      @result{} ans =
+##         "ab ab ab "
 ##         "cdecdecde"
 ## @end group
 ## @end example
+##
+## @example
+## @group
+## s = @{ "ab"; "cde" @};
+## strcat (s, s, s)
+##      @result{} ans =
+##         @{
+##           [1,1] = ababab
+##           [2,1] = cdecdecde
+##         @}
+## @end group
+## @end example
+##
+## @seealso{cstrcat, char, strvcat}
 ## @end deftypefn
 
 ## Author: jwe
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strcmpi.m
--- a/scripts/strings/strcmpi.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strcmpi.m Fri Dec 26 23:40:05 2008 +0100
@@ -18,8 +18,8 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} strcmpi (@var{s1}, @var{s2})
-## Ignoring case, return 1 if the character strings @var{s1} and @var{s2}
-## are the same, and 0 otherwise.
+## Ignoring case, return 1 if the character strings (or character
+## arrays) @var{s1} and @var{s2} are the same, and 0 otherwise.
 ##
 ## If either @var{s1} or @var{s2} is a cell array of strings, then an array
 ## of the same size is returned, containing the values described above for
@@ -51,3 +51,5 @@
   endif
 
 endfunction
+
+%!assert (strcmpi("abc123", "ABC123"), logical(1));
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strfind.m
--- a/scripts/strings/strfind.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strfind.m Fri Dec 26 23:40:05 2008 +0100
@@ -26,8 +26,26 @@
 ##
 ## 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}
+## above. Examples:
+##
+## @example
+## @group
+## strfind ("abababa", "aba")
+##      @result{} [1, 3, 5]
+##
+## strfind (@{"abababa", "bebebe", "ab"@}, "aba")
+##      @result{} ans =
+##         @{
+##           [1,1] =
+##
+##              1   3   5
+##
+##           [1,2] = [](1x0)
+##           [1,3] = [](1x0)
+##         @}
+## @end group
+## @end example
+## @seealso{findstr, strmatch, strcmp, strncmp, strcmpi, strncmpi, find}
 ## @end deftypefn
 
 ## Author: alois schloegl <address@hidden>
@@ -66,3 +84,11 @@
   endwhile
 
 ### endfunction
+
+%!error <Invalid call to strfind> strfind ();
+%!error <Invalid call to strfind> strfind ("foo", "bar", 1);
+%!error <pattern must be a string value> strfind ("foo", 100);
+%!error <text must be a string or cell array of string> strfind (100, "foo");
+
+%!assert (strfind ("abababa", "aba"), [1, 3, 5]);
+%!assert (strfind ({"abababa", "bla", "bla"}, "a"), {[1, 3, 5, 7], 3, 3});
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strjust.m
--- a/scripts/strings/strjust.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strjust.m Fri Dec 26 23:40:05 2008 +0100
@@ -21,7 +21,18 @@
 ## Shift the non-blank text of @var{s} to the left, right or center of
 ## the string.  If @var{s} is a string array, justify each string in the
 ## array.  Null characters are replaced by blanks.  If no justification
-## is specified, then all rows are right-justified.
+## is specified, then all rows are right-justified. For example:
+##
+## @example
+## @group
+## strjust (["a"; "ab"; "abc"; "abcd"])
+##      @result{} ans =
+##            a
+##           ab
+##          abc
+##         abcd
+## @end group
+## @end example
 ## @end deftypefn
 
 function x = strjust (x, just)
@@ -63,3 +74,10 @@
   x = x (idx*nr + [1:nr]'*ones(1,nc));
 
 endfunction
+
+%!error <Invalid call to strjust> strjust();
+%!error <Invalid call to strjust> strjust(["a";"ab"], "center", 1);
+%!assert (strjust (["a"; "ab"; "abc"; "abcd"]),
+%!        ["   a";"  ab"; " abc"; "abcd"]);
+%!assert (strjust (["a"; "ab"; "abc"; "abcd"], "center"),
+%!        [" a  "; " ab"; "abc "; "abcd"]);
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strmatch.m
--- a/scripts/strings/strmatch.m        Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strmatch.m        Fri Dec 26 23:40:05 2008 +0100
@@ -23,7 +23,22 @@
 ## The second argument @var{a} may be a string matrix or a cell array of
 ## strings.  If the third argument @code{"exact"} is not given, then
 ## @var{s} only needs to match @var{a} up to the length of @var{s}.  Nul
-## characters match blanks.  Results are returned as a column vector.
+## characters match blanks.  Results are returned as a column vector. 
+## For example:
+##
+## @example
+## @group
+## strmatch ("apple", "apple juice")
+##      @result{} 1
+##
+## strmatch ("apple", ["apple pie"; "apple juice"; "an apple"])
+##      @result{} [1; 2]
+##
+## strmatch ("apple", @{"apple pie"; "apple juice"; "tomato"@})
+##      @result{} [1; 2]
+## @end group
+## @end example
+## @seealso{strfind, findstr, strcmp, strncmp, strcmpi, strncmpi, find}
 ## @end deftypefn
 
 ## Author: Paul Kienzle, Alois Schloegl
@@ -66,3 +81,13 @@
   endif
     
 endfunction 
+
+%!error <Invalid call to strmatch> strmatch();
+%!error <Invalid call to strmatch> strmatch("a", "aaa", "exact", 1);
+%!assert (strmatch("a", {"aaa", "bab", "bbb"}), 1);
+%!assert (strmatch ("apple", "apple juice"), 1);
+%!assert (strmatch ("apple", ["apple pie"; "apple juice"; "an apple"]),
+%!        [1; 2]);
+%!assert (strmatch ("apple", {"apple pie"; "apple juice"; "tomato"}),
+%!        [1; 2]);
+%!assert (strmatch ("apple pie", "apple"), []);
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strncmpi.m
--- a/scripts/strings/strncmpi.m        Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strncmpi.m        Fri Dec 26 23:40:05 2008 +0100
@@ -19,11 +19,12 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} strncmpi (@var{s1}, @var{s2}, @var{n})
 ## Ignoring case, return 1 if the first @var{n} characters of character
-## strings @var{s1} and @var{s2} are the same, and 0 otherwise.
+## strings (or character arrays) @var{s1} and @var{s2} are the same, and
+## 0 otherwise.
 ##
 ## If either @var{s1} or @var{s2} is a cell array of strings, then an array
 ## of the same size is returned, containing the values described above for
-## every member of the cell array. The other argument may also be a cell
+## every member of the cell array.  The other argument may also be a cell
 ## array of strings (of the same size or with only one element), char matrix
 ## or character string.
 ##
@@ -44,3 +45,5 @@
   endif
 
 endfunction
+
+%!assert (strncmpi("abc123", "ABC456", 3), logical(1));
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strrep.m
--- a/scripts/strings/strrep.m  Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strrep.m  Fri Dec 26 23:40:05 2008 +0100
@@ -26,6 +26,7 @@
 ## strrep ("This is a test string", "is", "&%$")
 ##      @result{} "Th&%$ &%$ a test string"
 ## @end example
+## @seealso{regexprep, strfind, findstr}
 ## @end deftypefn
 
 ## Author: Kurt Hornik <address@hidden>
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strtok.m
--- a/scripts/strings/strtok.m  Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strtok.m  Fri Dec 26 23:40:05 2008 +0100
@@ -22,8 +22,21 @@
 ## Find all characters up to but not including the first character which
 ## is in the string delim.  If @var{rem} is requested, it contains the
 ## remainder of the string, starting at the first deliminator. Leading
-## delimiters are ignored.  If @var{delim} is not specified, space is assumed.
+## delimiters are ignored.  If @var{delim} is not specified, space is
+## assumed.  For example: 
 ##
+## @example
+## @group
+## strtok ("this is the life")
+##      @result{} "this"
+##
+## [tok, rem] = strtok ("14*27+31", "+-*/")
+##      @result{}
+##         tok = 14
+##         rem = *27+31
+## @end group
+## @end example
+## @seealso{index, split}
 ## @end deftypefn
 
 ## FIXME: check what to do for a null delimiter
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strtrim.m
--- a/scripts/strings/strtrim.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strtrim.m Fri Dec 26 23:40:05 2008 +0100
@@ -21,7 +21,17 @@
 ## Remove leading and trailing blanks and nulls from @var{s}.  If
 ## @var{s} is a matrix, @var{strtrim} trims each row to the length of
 ## longest string.  If @var{s} is a cell array, operate recursively on
-## each element of the cell array. 
+## each element of the cell array. For example:
+##
+## @example
+## @group
+## strtrim ("    abc  ")
+##      @result{} "abc"
+##
+## strtrim ([" abc   "; "   def   "])
+##      @result{} ["abc  "; "  def"]
+## @end group
+## @end example
 ## @end deftypefn
 
 ## Author: John Swensen <address@hidden>
@@ -52,3 +62,8 @@
   endif
 
 endfunction
+
+%!error <Invalid call to strtrim> strtrim();
+%!error <Invalid call to strtrim> strtrim("abc", "def");
+%!assert (strtrim ("    abc  "), "abc");
+%!assert (strtrim ([" abc   "; "   def   "]), ["abc  "; "  def"]);
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strtrunc.m
--- a/scripts/strings/strtrunc.m        Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strtrunc.m        Fri Dec 26 23:40:05 2008 +0100
@@ -19,7 +19,7 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} strtrunc (@var{s}, @var{n})
 ## Truncate the character string @var{s} to length @var{n}. If @var{s}
-## is a char matrix, then the number of columns are adjusted.
+## is a char matrix, then the number of columns is adjusted.
 ##
 ## If @var{s} is a cell array of strings, then the operation is performed
 ## on its members and the new cell array is returned.
@@ -51,3 +51,9 @@
   endif
 
 endfunction
+
+%!error <Invalid call to strtrunc> strtrunc ();
+%!error <s must be a character string or a cell array of strings> strtrunc (1, 
1)
+%!assert (strtrunc("abcdefg", 4), "abcd");
+%!assert (strtrunc("abcdefg", 10), "abcdefg");
+%!assert (strtrunc({"abcdef", "fedcba"}, 3), {"abc", "fed"});
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/strvcat.m
--- a/scripts/strings/strvcat.m Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/strvcat.m Fri Dec 26 23:40:05 2008 +0100
@@ -18,11 +18,26 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} strvcat (@var{s_1}, @dots{}, @var{s_n})
-## Return a matrix containing the strings (and cell-strings) 
+## Return a character array containing the strings (or cell-strings) 
 ## @var{s_1}, @dots{}, @var{s_n} as
 ## its rows.  Each string is padded with blanks in order to form a valid
-## matrix.  Unlike @var{char}, empty strings are ignored.
-## @seealso{cstrcat, char}
+## matrix.  For numerical input, each element is converted to the
+## corresponding ASCII character.  Unlike @var{char}, empty strings are
+## removed. For example:
+##
+## @example
+## @group
+## strvcat ([97, 98, 99], "", @{"98", "99", address@hidden, ["num", "bers"])
+##     @result{} ans = 
+##        ["abc    "
+##         "98     "
+##         "99     "
+##         "d      "
+##         "numbers"]
+## @end group
+## @end example
+##
+## @seealso{char, cstrcat, strcat}
 ## @end deftypefn
 
 ## Author: Kurt Hornik <address@hidden>
diff -r a84d71abdc5b -r 14dbaf03110c scripts/strings/substr.m
--- a/scripts/strings/substr.m  Wed Dec 24 16:45:11 2008 -0500
+++ b/scripts/strings/substr.m  Fri Dec 26 23:40:05 2008 +0100
@@ -33,7 +33,7 @@
 ## @end example
 ##
 ## This function is patterned after AWK.  You can get the same result by
-## @address@hidden (@var{offset} : (@var{offset} + @var{len} - 1))}.
+## @address@hidden(@var{offset} : (@var{offset} + @var{len} - 1))}.
 ## @end deftypefn
 
 ## Author: Kurt Hornik <address@hidden>
diff -r a84d71abdc5b -r 14dbaf03110c src/ChangeLog
--- a/src/ChangeLog     Wed Dec 24 16:45:11 2008 -0500
+++ b/src/ChangeLog     Fri Dec 26 23:40:05 2008 +0100
@@ -0,0 +1,7 @@
+2008-12-26  Thorsten Meyer  <address@hidden>
+
+       * mappers.cc (Ftoascii), mappers.cc (Ftolower), mappers.cc
+       (Ftoupper), DLD-FUNCTIONS/regexp.cc (Fregexp),
+       DLD-FUNCTIONS/regexp.cc (Fregexpi), DLD-FUNCTIONS/regexp.cc
+       (Fregexprep): Add references.
+       
diff -r a84d71abdc5b -r 14dbaf03110c src/DLD-FUNCTIONS/regexp.cc
--- a/src/DLD-FUNCTIONS/regexp.cc       Wed Dec 24 16:45:11 2008 -0500
+++ b/src/DLD-FUNCTIONS/regexp.cc       Fri Dec 26 23:40:05 2008 +0100
@@ -994,6 +994,7 @@
 @item literalspacing\n\
 The pattern is taken literally.\n\
 @end table\n\
address@hidden, regexprep}\n\
 @end deftypefn")
 {
   octave_value_list retval;
@@ -1186,7 +1187,7 @@
 \n\
 Case insensitive regular expression string matching. Matches @var{pat} in\n\
 @var{str} and returns the position and matching substrings or empty values\n\
-if there are none. See @code{regexp} for more details\n\
+if there are none.  @xref{doc-regexp,,regexp}, for more details\n\
 @end deftypefn")
 {
   octave_value_list retval;
@@ -1569,7 +1570,7 @@
 Alternatively, use (?x) or (?-x) in the pattern.\n\
 \n\
 @end table\n\
address@hidden,regexpi}\n\
address@hidden,regexpi,strrep}\n\
 @end deftypefn")
 {
   octave_value_list retval;
diff -r a84d71abdc5b -r 14dbaf03110c src/mappers.cc
--- a/src/mappers.cc    Wed Dec 24 16:45:11 2008 -0500
+++ b/src/mappers.cc    Fri Dec 26 23:40:05 2008 +0100
@@ -1555,6 +1555,7 @@
 @end group\n\
 \n\
 @end example\n\
address@hidden
 @end deftypefn")
 {
   octave_value retval;
@@ -1578,6 +1579,7 @@
 tolower (\"MiXeD cAsE 123\")\n\
      @result{} \"mixed case 123\"\n\
 @end example\n\
address@hidden
 @end deftypefn")
 {
   octave_value retval;
@@ -1623,6 +1625,7 @@
      @result{} \"MIXED CASE 123\"\n\
 @end group\n\
 @end example\n\
address@hidden
 @end deftypefn")
 {
   octave_value retval;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]