Mercurial > hg > octave-terminal
changeset 8442:502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Mon, 05 Jan 2009 08:11:03 +0100 |
parents | cc3ac5eb6be3 |
children | 34c0acf11539 |
files | doc/ChangeLog doc/interpreter/strings.txi scripts/ChangeLog scripts/general/int2str.m scripts/general/num2str.m scripts/strings/base2dec.m scripts/strings/blanks.m scripts/strings/cstrcat.m scripts/strings/findstr.m scripts/strings/isletter.m scripts/strings/isstrprop.m scripts/strings/mat2str.m scripts/strings/regexptranslate.m scripts/strings/split.m scripts/strings/str2double.m scripts/strings/str2num.m scripts/strings/strcat.m scripts/strings/strcmpi.m scripts/strings/strfind.m scripts/strings/strjust.m scripts/strings/strmatch.m scripts/strings/strncmpi.m scripts/strings/strrep.m scripts/strings/strtok.m scripts/strings/strtrim.m scripts/strings/strtrunc.m scripts/strings/strvcat.m scripts/strings/substr.m src/ChangeLog src/DLD-FUNCTIONS/regexp.cc src/mappers.cc |
diffstat | 31 files changed, 384 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2008-12-26 Thorsten Meyer <thorsten.meyier@gmx.de> + + * interpreter/strings.txi: Add space to ischar example. + 2008-12-26 Francesco Potortì <pot@gnu.org> * interpreter/matrix.txi (Rearranging Matrices): Add reference
--- a/doc/interpreter/strings.txi +++ b/doc/interpreter/strings.txi @@ -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
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,18 @@ +2008-12-26 Thorsten Meyer <thorsten.meyier@gmx.de> + + * 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. + 2008-12-29 David Bateman <dbateman@free.fr> * goemetry/voronoi.m: Speed up and handle dense grids.
--- a/scripts/general/int2str.m +++ b/scripts/general/int2str.m @@ -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);
--- a/scripts/general/num2str.m +++ b/scripts/general/num2str.m @@ -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);
--- a/scripts/strings/base2dec.m +++ b/scripts/strings/base2dec.m @@ -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
--- a/scripts/strings/blanks.m +++ b/scripts/strings/blanks.m @@ -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
--- a/scripts/strings/cstrcat.m +++ b/scripts/strings/cstrcat.m @@ -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
--- a/scripts/strings/findstr.m +++ b/scripts/strings/findstr.m @@ -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]));
--- a/scripts/strings/isletter.m +++ b/scripts/strings/isletter.m @@ -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");
--- a/scripts/strings/isstrprop.m +++ b/scripts/strings/isstrprop.m @@ -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
--- a/scripts/strings/mat2str.m +++ b/scripts/strings/mat2str.m @@ -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 <fabian@tu-cottbus.de>
--- a/scripts/strings/regexptranslate.m +++ b/scripts/strings/regexptranslate.m @@ -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", '$.?[]'), '\$\.\?\[\]')
--- a/scripts/strings/split.m +++ b/scripts/strings/split.m @@ -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 <Kurt.Hornik@wu-wien.ac.at>
--- a/scripts/strings/str2double.m +++ b/scripts/strings/str2double.m @@ -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 <a.schloegl@ieee.org> @@ -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]);
--- a/scripts/strings/str2num.m +++ b/scripts/strings/str2num.m @@ -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
--- a/scripts/strings/strcat.m +++ b/scripts/strings/strcat.m @@ -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
--- a/scripts/strings/strcmpi.m +++ b/scripts/strings/strcmpi.m @@ -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));
--- a/scripts/strings/strfind.m +++ b/scripts/strings/strfind.m @@ -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 <a.schloegl@ieee.org> @@ -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});
--- a/scripts/strings/strjust.m +++ b/scripts/strings/strjust.m @@ -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"]);
--- a/scripts/strings/strmatch.m +++ b/scripts/strings/strmatch.m @@ -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"), []);
--- a/scripts/strings/strncmpi.m +++ b/scripts/strings/strncmpi.m @@ -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));
--- a/scripts/strings/strrep.m +++ b/scripts/strings/strrep.m @@ -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 <Kurt.Hornik@wu-wien.ac.at>
--- a/scripts/strings/strtok.m +++ b/scripts/strings/strtok.m @@ -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
--- a/scripts/strings/strtrim.m +++ b/scripts/strings/strtrim.m @@ -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 <jpswensen@jhu.edu> @@ -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"]);
--- a/scripts/strings/strtrunc.m +++ b/scripts/strings/strtrunc.m @@ -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"});
--- a/scripts/strings/strvcat.m +++ b/scripts/strings/strvcat.m @@ -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", 100@}, ["num", "bers"]) +## @result{} ans = +## ["abc " +## "98 " +## "99 " +## "d " +## "numbers"] +## @end group +## @end example +## +## @seealso{char, cstrcat, strcat} ## @end deftypefn ## Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
--- a/scripts/strings/substr.m +++ b/scripts/strings/substr.m @@ -33,7 +33,7 @@ ## @end example ## ## This function is patterned after AWK. You can get the same result by -## @code{@var{s} (@var{offset} : (@var{offset} + @var{len} - 1))}. +## @code{@var{s}(@var{offset} : (@var{offset} + @var{len} - 1))}. ## @end deftypefn ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2008-12-26 Thorsten Meyer <thorsten.meyier@gmx.de> + + * 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. + 2008-12-27 Jaroslav Hajek <highegg@gmail.com> * oct-obj.h, oct-obj.cc (octave_value_list::valid_scalar_indices): Remove.
--- a/src/DLD-FUNCTIONS/regexp.cc +++ b/src/DLD-FUNCTIONS/regexp.cc @@ -994,6 +994,7 @@ @item literalspacing\n\ The pattern is taken literally.\n\ @end table\n\ +@seealso{regexpi, 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\ -@seealso{regexp,regexpi}\n\ +@seealso{regexp,regexpi,strrep}\n\ @end deftypefn") { octave_value_list retval;
--- a/src/mappers.cc +++ b/src/mappers.cc @@ -1555,6 +1555,7 @@ @end group\n\ \n\ @end example\n\ +@seealso{char}\n\ @end deftypefn") { octave_value retval; @@ -1578,6 +1579,7 @@ tolower (\"MiXeD cAsE 123\")\n\ @result{} \"mixed case 123\"\n\ @end example\n\ +@seealso{toupper}\n\ @end deftypefn") { octave_value retval; @@ -1623,6 +1625,7 @@ @result{} \"MIXED CASE 123\"\n\ @end group\n\ @end example\n\ +@seealso{tolower}\n\ @end deftypefn") { octave_value retval;