annotate scripts/strings/isstrprop.m @ 9051:1bf0ce0930be

Grammar check TexInfo in all .m files Cleanup documentation sources to follow a few consistent rules. Spellcheck was NOT done. (but will be in another changeset)
author Rik <rdrider0-list@yahoo.com>
date Fri, 27 Mar 2009 22:31:03 -0700
parents eb63fbe60fab
children 95c3e38098bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8442
diff changeset
1 ## Copyright (C) 2008, 2009 John W. Eaton
7530
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## your option) any later version.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ## General Public License for more details.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 ## @deftypefn {Function File} {} isstrprop (@var{str}, @var{pred})
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 ## Test character string properties. For example,
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 ## @example
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ## @group
8442
502e58a0d44f Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7530
diff changeset
25 ## isstrprop ("abc123", "alpha")
7530
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 ## @result{} [1, 1, 1, 0, 0, 0]
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 ## @end group
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 ## @end example
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 ## If @var{str} is a cell array, @code{isstrpop} is applied recursively
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 ## to each element of the cell array.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 ## Numeric arrays are converted to character strings.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 ## The second argument @var{pred} may be one of
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 ## @table @code
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 ## @item "alpha"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 ## True for characters that are alphabetic
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 ## @item "alnum"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 ## @itemx "alphanum"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 ## True for characters that are alphabetic or digits.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 ## @item "ascii"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 ## True for characters that are in the range of ASCII encoding.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 ## @item "cntrl"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 ## True for control characters.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 ## @item "digit"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 ## True for decimal digits.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 ## @item "graph"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 ## @itemx "graphic"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 ## True for printing characters except space.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 ## @item "lower"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 ## True for lower-case letters.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 ## @item "print"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 ## True for printing characters including space.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 ## @item "punct"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 ## True for printing characters except space or letter or digit.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 ## @item "space"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 ## @itemx "wspace"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 ## True for whitespace characters (space, formfeed, newline, carriage
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 ## return, tab, vertical tab).
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 ## @item "upper"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 ## True for upper-case letters.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 ## @item "xdigit"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 ## True for hexadecimal digits.
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 ## @end table
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 ##
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 ## @seealso{isalnum, isalpha, isascii, iscntrl, isdigit, isgraph,
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 ## islower, isprint, ispunct, isspace, isupper, isxdigit}
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 ## @end deftypefn
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 function retval = isstrprop (str, pred)
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 if (nargin == 2)
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 switch (pred)
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 case "alpha"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 retval = isalpha (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 case {"alnum", "alphanum"}
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 retval = isalnum (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 case "ascii"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 retval = isascii (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 case "cntrl"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 retval = iscntrl (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 case "digit"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 retval = isdigit (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 case {"graph", "graphic"}
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 retval = isgraph (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 case "lower"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 retval = islower (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 case "print"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 retval = isprint (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 case "punct"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 retval = ispunct (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 case {"space", "wspace"}
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 retval = isspace (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 case "upper"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 retval = isupper (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 case "xdigit"
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 retval = isxdigit (str);
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 otherwise
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 error ("isstrprop: invalid predicate");
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 endswitch
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 else
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 print_usage ();
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 endif
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 endfunction
8442
502e58a0d44f Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7530
diff changeset
119
502e58a0d44f Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7530
diff changeset
120 %!error <invalid predicate> isstrprop ("abc123", "foo");
502e58a0d44f Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7530
diff changeset
121 %!assert (isstrprop ("abc123", "alpha"), logical ([1, 1, 1, 0, 0, 0]));