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