Mercurial > hg > octave-lyh
annotate scripts/strings/isstrprop.m @ 17428:577a19afdaf5
maint: Backed out changeset f81401b6b1f7.
* test/parser.tst: bug #33304 should remain an error until it is fixed.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 14 Sep 2013 17:07:05 -0700 |
parents | bc924baa2c4e |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13312
diff
changeset
|
1 ## Copyright (C) 2008-2012 John W. Eaton |
7530 | 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 -*- | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
20 ## @deftypefn {Function File} {} isstrprop (@var{str}, @var{prop}) |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
21 ## Test character string properties. For example: |
7530 | 22 ## |
23 ## @example | |
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 | 26 ## @result{} [1, 1, 1, 0, 0, 0] |
27 ## @end group | |
28 ## @end example | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
29 ## |
7530 | 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 ## | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
35 ## The second argument @var{prop} must be one of |
7530 | 36 ## |
11595
5ec6aa05638d
Prevent doubled quotes around @table items in Info.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
37 ## @table @asis |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
38 ## @item @qcode{"alpha"} |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
39 ## True for characters that are alphabetic (letters). |
7530 | 40 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
41 ## @item @qcode{"alnum"} |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
42 ## @itemx @qcode{"alphanum"} |
7530 | 43 ## True for characters that are alphabetic or digits. |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
44 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
45 ## @item @qcode{"lower"} |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
46 ## True for lowercase letters. |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
47 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
48 ## @item @qcode{"upper"} |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11595
diff
changeset
|
49 ## True for uppercase letters. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
50 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
51 ## @item @qcode{"digit"} |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
52 ## True for decimal digits (0-9). |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
53 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
54 ## @item @qcode{"xdigit"} |
11591
1d13679b587e
Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
55 ## True for hexadecimal digits (@nospell{a-fA-F0-9}). |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
56 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
57 ## @item @qcode{"space"} |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
58 ## @itemx @qcode{"wspace"} |
7530 | 59 ## True for whitespace characters (space, formfeed, newline, carriage |
60 ## return, tab, vertical tab). | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
61 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
62 ## @item @qcode{"punct"} |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
63 ## True for punctuation characters (printing characters except space |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
64 ## or letter or digit). |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
65 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
66 ## @item @qcode{"cntrl"} |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
67 ## True for control characters. |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
68 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
69 ## @item @qcode{"graph"} |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
70 ## @itemx @qcode{"graphic"} |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
71 ## True for printing characters except space. |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
72 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
73 ## @item @qcode{"print"} |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
74 ## True for printing characters including space. |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
75 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17178
diff
changeset
|
76 ## @item @qcode{"ascii"} |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
77 ## True for characters that are in the range of ASCII encoding. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
78 ## |
7530 | 79 ## @end table |
80 ## | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
81 ## @seealso{isalpha, isalnum, islower, isupper, isdigit, isxdigit, |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
82 ## isspace, ispunct, iscntrl, isgraph, isprint, isascii} |
7530 | 83 ## @end deftypefn |
84 | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
85 function retval = isstrprop (str, prop) |
7530 | 86 |
13312
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
87 if (nargin != 2) |
7530 | 88 print_usage (); |
89 endif | |
90 | |
13312
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
91 switch (prop) |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
92 case "alpha" |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
93 retval = isalpha (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
94 case {"alnum", "alphanum"} |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
95 retval = isalnum (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
96 case "ascii" |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
97 retval = isascii (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
98 case "cntrl" |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
99 retval = iscntrl (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
100 case "digit" |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
101 retval = isdigit (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
102 case {"graph", "graphic"} |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
103 retval = isgraph (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
104 case "lower" |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
105 retval = islower (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
106 case "print" |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
107 retval = isprint (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
108 case "punct" |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
109 retval = ispunct (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
110 case {"space", "wspace"} |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
111 retval = isspace (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
112 case "upper" |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
113 retval = isupper (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
114 case "xdigit" |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
115 retval = isxdigit (str); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
116 otherwise |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
117 error ("isstrprop: invalid string property"); |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
118 endswitch |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
119 |
7530 | 120 endfunction |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7530
diff
changeset
|
121 |
13312
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
122 |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
123 %!assert (isstrprop ("abc123", "alpha"), logical ([1, 1, 1, 0, 0, 0])) |
13312
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
124 %!assert (isstrprop ("abc123", "digit"), logical ([0, 0, 0, 1, 1, 1])) |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
125 %!assert (isstrprop ("Hello World", "wspace"), isspace ("Hello World")) |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
126 %!assert (isstrprop ("Hello World", "graphic"), isgraph ("Hello World")) |
13312
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
127 %!assert (isstrprop (char ("AbC", "123"), "upper"), logical ([1 0 1; 0 0 0])) |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
128 %!assert (isstrprop ({"AbC", "123"}, "lower"), {logical([0 1 0]), logical([0 0 0])}) |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
129 |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
130 %%Input Validation |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
131 %!error isstrprop () |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
132 %!error isstrprop ("abc123") |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
133 %!error isstrprop ("abc123", "alpha", "alpha") |
13312
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
134 %!error <invalid string property> isstrprop ("abc123", "foo") |
e84d512b2438
isstrprop.m: Put input validation first and add a few more tests.
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
135 |