annotate libinterp/octave-value/ov-ch-mat.cc @ 18129:e473c4853afc gui-release

enable non-integer ranges as indices by default and deprecate preference * octave.cc (maximum_braindamage): Don't call Fdo_brainded_shortcircuit_evaluation. * error.cc (initialize_default_warning_state): Don't set Octave:noninteger-range-as-index to "error". * octave.cc (maximum_braindamage): Don't call Fallow_noninteger_range_as_index. Don't set Octave:noninteger-range-as-index to "on". * ov-range.h, ov-range.cc (Vallow_noninteger_range_as_index): Now static. Set default value to true. * ov.h (octave_value::index_vector): New arg, require_integers. * ov-base.cc, ov-base.h (octave_value::index_vector): Likewise. * ov-base-diag.cc, ov-base-diag.h, ov-bool-mat.h, ov-bool-sparse.h, ov-bool.h, ov-ch-mat.cc, ov-ch-mat.h, ov-class.cc, ov-class.h, ov-colon.h, ov-complex.h, ov-float.h, ov-flt-re-mat.h, ov-intx.h, ov-lazy-idx.h, ov-perm.cc, ov-perm.h, ov-range.cc, ov-range.h, ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h, ov-scalar.h: Make corresponding changes in all derived methods. * ov-range.cc (octave_range::index_vector): If new require_integers argument is true, also require integer arguments regardless of the setting of Vallow_noninteger_range_as_index. * utils.cc (Fisindex): Don't temporarily set Vallow_noninteger_range_as_index. Call index_vector with argument of true. * NEWS: Mention change in default value, warning state and deprecated function.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Dec 2013 23:35:34 -0500
parents 175b392e91fe
children 4197fc428c7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
1 /*
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
2
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 15850
diff changeset
3 Copyright (C) 1996-2013 John W. Eaton
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
4 Copyright (C) 2009-2010 VZLU Prague
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
5
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
7
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6720
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6720
diff changeset
11 option) any later version.
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
12
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
16 for more details.
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
17
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6720
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6720
diff changeset
20 <http://www.gnu.org/licenses/>.
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
21
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
22 */
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
23
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
26 #endif
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
27
9941
1369f13ae6b2 several fixes by M. Goffioul
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
28 #include <cctype>
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3221
diff changeset
29 #include <iostream>
2901
e6d25bc478dd [project @ 1997-04-30 03:41:26 by jwe]
jwe
parents: 2847
diff changeset
30
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
31 #include "lo-ieee.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
32 #include "mx-base.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
33
15149
62a35ae7d6a2 use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents: 15057
diff changeset
34 #include "mxarray.h"
3219
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3136
diff changeset
35 #include "ov-base.h"
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3136
diff changeset
36 #include "ov-base-mat.h"
30770ba4457a [project @ 1998-11-13 03:44:31 by jwe]
jwe
parents: 3136
diff changeset
37 #include "ov-base-mat.cc"
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
38 #include "ov-ch-mat.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
39 #include "gripes.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
40 #include "pr-output.h"
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
41
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4455
diff changeset
42 template class octave_base_matrix<charNDArray>;
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
43
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
44 idx_vector
18129
e473c4853afc enable non-integer ranges as indices by default and deprecate preference
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
45 octave_char_matrix::index_vector (bool /* require_integers */) const
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
46 {
6720
fa2f5d4e55db [project @ 2007-06-14 01:18:25 by dbateman]
dbateman
parents: 6686
diff changeset
47 const char *p = matrix.data ();
fa2f5d4e55db [project @ 2007-06-14 01:18:25 by dbateman]
dbateman
parents: 6686
diff changeset
48 if (numel () == 1 && *p == ':')
fa2f5d4e55db [project @ 2007-06-14 01:18:25 by dbateman]
dbateman
parents: 6686
diff changeset
49 return idx_vector (':');
fa2f5d4e55db [project @ 2007-06-14 01:18:25 by dbateman]
dbateman
parents: 6686
diff changeset
50 else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
51 return idx_vector (array_value (true));
6720
fa2f5d4e55db [project @ 2007-06-14 01:18:25 by dbateman]
dbateman
parents: 6686
diff changeset
52 }
fa2f5d4e55db [project @ 2007-06-14 01:18:25 by dbateman]
dbateman
parents: 6686
diff changeset
53
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
54 double
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
55 octave_char_matrix::double_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
56 {
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
57 double retval = lo_ieee_nan_value ();
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
58
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
59 if (rows () > 0 && columns () > 0)
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
60 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
61 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
62 "character matrix", "real scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
63
8956
d91fa4b20bbb ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
64 retval = static_cast<unsigned char> (matrix (0, 0));
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
65 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
66 else
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
67 gripe_invalid_conversion ("character matrix", "real scalar");
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
68
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
69 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
70 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
71
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
72 float
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
73 octave_char_matrix::float_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
74 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
75 float retval = lo_ieee_float_nan_value ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
76
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
77 if (rows () > 0 && columns () > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
78 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
79 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
80 "character matrix", "real scalar");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
81
8956
d91fa4b20bbb ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
82 retval = static_cast<unsigned char> (matrix (0, 0));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
83 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
84 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
85 gripe_invalid_conversion ("character matrix", "real scalar");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
86
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
87 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
88 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
89
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
90 Complex
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
91 octave_char_matrix::complex_value (bool) const
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
92 {
4102
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
93 double tmp = lo_ieee_nan_value ();
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
94
cbac6756967e [project @ 2002-10-14 20:16:44 by jwe]
jwe
parents: 4066
diff changeset
95 Complex retval (tmp, tmp);
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
96
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
97 if (rows () > 0 && columns () > 0)
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
98 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
99 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
100 "character matrix", "complex scalar");
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
101
8956
d91fa4b20bbb ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
102 retval = static_cast<unsigned char> (matrix (0, 0));
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4192
diff changeset
103 }
2376
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
104 else
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
105 gripe_invalid_conversion ("character matrix", "complex scalar");
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
106
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
107 return retval;
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
108 }
2142216bf85a [project @ 1996-10-12 01:39:07 by jwe]
jwe
parents:
diff changeset
109
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
110 FloatComplex
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
111 octave_char_matrix::float_complex_value (bool) const
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
112 {
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
113 float tmp = lo_ieee_float_nan_value ();
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
114
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
115 FloatComplex retval (tmp, tmp);
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
116
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
117 if (rows () > 0 && columns () > 0)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
118 {
14469
29aabe9b37a2 Rename array-as-vector, array-as-scalar warning IDs to match documentation (bug #35838)
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
119 gripe_implicit_conversion ("Octave:array-to-scalar",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
120 "character matrix", "complex scalar");
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
121
8956
d91fa4b20bbb ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
122 retval = static_cast<unsigned char> (matrix (0, 0));
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
123 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
124 else
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
125 gripe_invalid_conversion ("character matrix", "complex scalar");
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
126
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
127 return retval;
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
128 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
129
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
130 void
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
131 octave_char_matrix::print_raw (std::ostream& os,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
132 bool pr_as_read_syntax) const
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
133 {
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
134 octave_print_internal (os, matrix, pr_as_read_syntax,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
135 current_print_indent_level ());
4643
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
136 }
ef3a14fb6847 [project @ 2003-11-22 12:25:44 by jwe]
jwe
parents: 4612
diff changeset
137
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
138 mxArray *
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
139 octave_char_matrix::as_mxArray (void) const
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
140 {
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
141 mxArray *retval = new mxArray (mxCHAR_CLASS, dims (), mxREAL);
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
142
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
143 mxChar *pr = static_cast<mxChar *> (retval->get_data ());
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
144
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 5900
diff changeset
145 mwSize nel = numel ();
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
146
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
147 const char *p = matrix.data ();
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
148
6686
2aad75fcc93a [project @ 2007-06-03 20:58:28 by dbateman]
dbateman
parents: 5900
diff changeset
149 for (mwIndex i = 0; i < nel; i++)
5900
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
150 pr[i] = p[i];
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
151
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
152 return retval;
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
153 }
c20eb7330d13 [project @ 2006-07-22 08:31:16 by jwe]
jwe
parents: 5781
diff changeset
154
15491
c9844b82945f reformat interesting comment
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15452
diff changeset
155 // The C++ standard guarantees cctype defines functions, not macros (and
c9844b82945f reformat interesting comment
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15452
diff changeset
156 // hence macros *CAN'T* be defined if only cctype is included) so
15850
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
157 // there's no need to fuck around. The exceptions are isascii and
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
158 // toascii, which are not C++. Oddly enough, all those character
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
159 // functions are int (*) (int), even in C++. Wicked!
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
160 static inline int xisascii (int c)
15850
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
161 {
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
162 #ifdef HAVE_ISASCII
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
163 return isascii (c);
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
164 #else
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
165 return (c >= 0x00 && c <= 0x7f);
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
166 #endif
ffd1a99733bd build: Check for isascii() before using it.
Rik <rik@octave.org>
parents: 15501
diff changeset
167 }
9689
34d6f005db4b eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents: 8956
diff changeset
168
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
169 static inline int xtoascii (int c)
15452
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15195
diff changeset
170 {
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15195
diff changeset
171 #ifdef HAVE_TOASCII
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15195
diff changeset
172 return toascii (c);
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15195
diff changeset
173 #else
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15195
diff changeset
174 return (c & 0x7F);
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15195
diff changeset
175 #endif
4d960b078272 build: Remove unnecessary AC_CHECK_FUNCS calls.
Rik <rik@octave.org>
parents: 15195
diff changeset
176 }
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
177
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
178 octave_value
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
179 octave_char_matrix::map (unary_mapper_t umap) const
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
180 {
15501
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
181 octave_value retval;
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
182
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
183 switch (umap)
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
184 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
185 #define STRING_MAPPER(UMAP,FCN,TYPE) \
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
186 case umap_ ## UMAP: \
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
187 return octave_value (matrix.map<TYPE, int (&) (int)> (FCN))
9689
34d6f005db4b eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents: 8956
diff changeset
188
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
189 STRING_MAPPER (xisalnum, std::isalnum, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
190 STRING_MAPPER (xisalpha, std::isalpha, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
191 STRING_MAPPER (xisascii, xisascii, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
192 STRING_MAPPER (xiscntrl, std::iscntrl, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
193 STRING_MAPPER (xisdigit, std::isdigit, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
194 STRING_MAPPER (xisgraph, std::isgraph, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
195 STRING_MAPPER (xislower, std::islower, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
196 STRING_MAPPER (xisprint, std::isprint, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
197 STRING_MAPPER (xispunct, std::ispunct, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
198 STRING_MAPPER (xisspace, std::isspace, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
199 STRING_MAPPER (xisupper, std::isupper, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
200 STRING_MAPPER (xisxdigit, std::isxdigit, bool);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
201 STRING_MAPPER (xtoascii, xtoascii, double);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
202 STRING_MAPPER (xtolower, std::tolower, char);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
203 STRING_MAPPER (xtoupper, std::toupper, char);
9689
34d6f005db4b eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents: 8956
diff changeset
204
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
205 // For Matlab compatibility, these should work on ASCII values
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
206 // without error or warning.
15501
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
207 case umap_abs:
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
208 case umap_ceil:
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
209 case umap_fix:
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
210 case umap_floor:
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
211 case umap_imag:
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
212 case umap_isinf:
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
213 case umap_isnan:
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
214 case umap_real:
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
215 case umap_round:
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
216 {
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
217 octave_matrix m (array_value (true));
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
218 return m.map (umap);
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
219 }
15501
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
220
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
221 default:
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
222 error ("%s: expecting numeric argument", get_umap_name (umap));
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
223 break;
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
224 }
15501
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
225
814c4b0d5c49 make numeric mapper functions throw error for char args (bug #37535)
John W. Eaton <jwe@octave.org>
parents: 15491
diff changeset
226 return retval;
9812
f80c566bc751 improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents: 9690
diff changeset
227 }